generated from rexzhang/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runserver.py
executable file
·42 lines (33 loc) · 986 Bytes
/
runserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
from logging import getLogger
from os import getenv
import click
import uvicorn
logger = getLogger(__name__)
@click.command()
@click.option(
"-H",
"--host",
default="0.0.0.0",
help="Bind socket to this host. [default: 0.0.0.0]",
)
@click.option(
"-P", "--port", default=8000, help="Bind socket to this port. [default: 8000]"
)
@click.option("--dev", is_flag=True, help="for dev stage")
def cli(**cli_kwargs):
kwargs = {
"app": "ddns_clienter.asgi:application",
"lifespan": "off", # TODO: ASGI 'lifespan' protocol appears unsupported. Django 3.1.x
"log_level": "info",
"access_log": False,
}
kwargs.update(cli_kwargs)
dev = kwargs.pop("dev", False)
debug = getenv("DEBUG", False)
if dev or debug:
print("!!!Enter Development Stage...!!!")
kwargs.update({"access_log": True, "reload": True})
return uvicorn.run(**kwargs)
if __name__ == "__main__":
cli()