This commit is contained in:
57
server.py
57
server.py
@@ -1,13 +1,8 @@
|
||||
import sys
|
||||
import os
|
||||
import uvicorn
|
||||
from uvicorn.main import logger
|
||||
|
||||
from settings import PORT, DEV_SERVER_PID_FILE_NAME
|
||||
|
||||
|
||||
def exception_handler(exception_type, exception, traceback, debug_hook=sys.excepthook):
|
||||
print("%s: %s" % (exception_type.__name__, exception))
|
||||
|
||||
from settings import PORT
|
||||
|
||||
log_settings = {
|
||||
"version": 1,
|
||||
@@ -53,36 +48,20 @@ local_headers = [
|
||||
("Access-Control-Allow-Credentials", "true"),
|
||||
]
|
||||
|
||||
if __name__ == "__main__":
|
||||
x = ""
|
||||
if len(sys.argv) > 1:
|
||||
x = sys.argv[1]
|
||||
if x == "dev":
|
||||
if os.path.exists(DEV_SERVER_PID_FILE_NAME):
|
||||
os.remove(DEV_SERVER_PID_FILE_NAME)
|
||||
want_reload = False
|
||||
if "reload" in sys.argv:
|
||||
print("MODE: DEV + RELOAD")
|
||||
want_reload = True
|
||||
else:
|
||||
print("MODE: DEV")
|
||||
|
||||
uvicorn.run(
|
||||
"main:dev_app",
|
||||
host="localhost",
|
||||
port=8080,
|
||||
headers=local_headers,
|
||||
# log_config=log_settings,
|
||||
log_level=None,
|
||||
access_log=True,
|
||||
reload=want_reload,
|
||||
) # , ssl_keyfile="discours.key", ssl_certfile="discours.crt")
|
||||
else:
|
||||
sys.excepthook = exception_handler
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host="0.0.0.0",
|
||||
port=PORT,
|
||||
proxy_headers=True,
|
||||
server_header=True,
|
||||
)
|
||||
def exception_handler(_et, exc, _tb):
|
||||
logger.error(..., exc_info=(type(exc), exc, exc.__traceback__))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.excepthook = exception_handler
|
||||
if "dev" in sys.argv:
|
||||
import os
|
||||
os.environ.set("MODE", "development")
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host="0.0.0.0",
|
||||
port=PORT,
|
||||
proxy_headers=True,
|
||||
server_header=True
|
||||
)
|
||||
|
Reference in New Issue
Block a user