-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
58 lines (47 loc) · 1.45 KB
/
run.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
48
49
50
51
52
53
54
55
56
57
58
import os
import uvicorn
from starlette.middleware.cors import CORSMiddleware
from fastapi import FastAPI
from loguru import logger
import config
from config import PORT, BIND, WORKERS, RELOAD
from api.views.index import app
from config import PORT, LOGFILE, ORIGINS, BASEDIR, LOGDIR
if __name__ == "__main__":
uvicorn.run("api:user",
host=BIND,
port=int(PORT),
reload=RELOAD,
workers=int(WORKERS),
)
LOGDIR = BASEDIR + "/" + LOGDIR
if not os.path.exists(LOGDIR):
os.makedirs(LOGDIR)
logger.add(LOGDIR + "/" + LOGFILE,
rotation="10MB",
colorize=True,
format="<green>{time:YYYYMMDD_HH:mm:ss}</green> | {level} | <level>{message}</level>",
level="ERROR")
global_app = FastAPI()
# Set all CORS enabled origins
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
global_app.include_router(app)
# global_app.add_middleware(
# CORSMiddleware,
# allow_origins=[
# "http://127.0.0.1:5200",
# "http://0.0.0.0:5200",
# "http://localhost:5200",
# "http://192.168.0.213:5200",
# ],
# allow_credentials=True,
# allow_methods=["*"],
# allow_headers=["*"],
# )