-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (36 loc) · 1.12 KB
/
main.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
43
44
45
46
47
import logging
from logging.config import fileConfig
import uvicorn
from settings import app_settings
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.routers.files import FILE_ROUTER
from fastapi.staticfiles import StaticFiles
DEBUG_FILE_CONFIG = 'config/logging_debug.ini'
PROD_FILE_CONFIG = 'config/logging_prod.ini'
LOGGER = logging.getLogger(app_settings.app_logger_name)
app = FastAPI()
app.include_router(FILE_ROUTER)
app.mount("/.well-known/pki-validation/", StaticFiles(directory="static"), name="static")
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
def settup_logging():
if app_settings.app_is_debug:
fileConfig(DEBUG_FILE_CONFIG)
else:
fileConfig(PROD_FILE_CONFIG)
def run_server():
LOGGER.info(f'starting server {app_settings.server_host} {app_settings.server_port}')
uvicorn.run(
app,
host=app_settings.server_host,
port=app_settings.server_port)
if __name__ == '__main__':
settup_logging()
run_server()