Simplify starting: create anonstream/__main__.py
このコミットが含まれているのは:
コミット
6746f7b859
23
README.md
23
README.md
|
@ -52,10 +52,11 @@ to know what they do:
|
|||
|
||||
Run it:
|
||||
```sh
|
||||
python -m uvicorn app:app --port 5051
|
||||
python -m anonstream
|
||||
```
|
||||
|
||||
This will start a webserver listening on the local host at port 5051.
|
||||
This will start a webserver listening on the local host at port 5051 (use
|
||||
`--port PORT` to override).
|
||||
|
||||
If you go to `http://localhost:5051` in a web browser now you should see
|
||||
the site. When you started the webserver some credentials were printed
|
||||
|
@ -68,6 +69,24 @@ setting up OBS Studio and a Tor onion service. If you want to use
|
|||
different streaming software and put your stream on the Internet some
|
||||
other way, read those instructions and copy the gist.
|
||||
|
||||
## Running
|
||||
|
||||
Start anonstream like this:
|
||||
```sh
|
||||
python -m anonstream
|
||||
```
|
||||
The default port is 5051. Append `--help` to see options.
|
||||
|
||||
If you want to use a different ASGI server, point it to the app factory
|
||||
at `asgi:create_app()`. For example with `uvicorn`:
|
||||
```sh
|
||||
python -m uvicorn asgi:create_app --factory --port 5051
|
||||
```
|
||||
|
||||
In either case you can explicitly set the location of the config file
|
||||
using the `ANONSTREAM_CONFIG` environment variable.
|
||||
|
||||
|
||||
## Hacking
|
||||
|
||||
anonstream has APIs for accessing internal state and hooking into
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
import argparse
|
||||
import os
|
||||
|
||||
import uvicorn
|
||||
|
||||
from anonstream import create_app
|
||||
|
||||
formatter = lambda prog: argparse.HelpFormatter(prog, max_help_position=26)
|
||||
parser = argparse.ArgumentParser(
|
||||
'python -m anonstream',
|
||||
description='Start the anonstream webserver locally.',
|
||||
formatter_class=formatter,
|
||||
)
|
||||
parser.add_argument(
|
||||
'--config', '-c',
|
||||
metavar='FILE',
|
||||
default=os.environ.get('ANONSTREAM_CONFIG', 'config.toml'),
|
||||
help=(
|
||||
'location of config.toml '
|
||||
'(default: $ANONSTREAM_CONFIG or ./config.toml)'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--port', '-p',
|
||||
type=int,
|
||||
default=5051,
|
||||
help='bind webserver to this port (default: 5051)',
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
app = create_app(args.config)
|
||||
uvicorn.run(app, port=args.port)
|
11
app.py
11
app.py
|
@ -1,11 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2022 n9k <https://git.076.ne.jp/ninya9k>
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import os
|
||||
import anonstream
|
||||
|
||||
config_file = os.path.join(os.path.dirname(__file__), 'config.toml')
|
||||
app = anonstream.create_app(config_file)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(port=5051, debug=True)
|
|
@ -0,0 +1,23 @@
|
|||
# SPDX-FileCopyrightText: 2022 n9k <https://git.076.ne.jp/ninya9k>
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
message = (
|
||||
'To start anonstream, run one of:\n'
|
||||
' $ python -m anonstream\n'
|
||||
' $ python -m uvicorn asgi:create_app --factory --port 5051\n'
|
||||
)
|
||||
print(message, file=sys.stderr, end='')
|
||||
exit(1)
|
||||
|
||||
import os
|
||||
import anonstream
|
||||
|
||||
config = os.environ.get(
|
||||
'ANONSTREAM_CONFIG',
|
||||
os.path.join(os.path.dirname(__file__), 'config.toml'),
|
||||
)
|
||||
|
||||
def create_app():
|
||||
return anonstream.create_app(config)
|
読み込み中…
新しいイシューから参照