-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (29 loc) · 923 Bytes
/
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
from fastapi import FastAPI
import uvicorn
from starlette.middleware.cors import CORSMiddleware
from routers import api
from util.class_object import singleton
from core.config import configs
@singleton
class AppCreator:
def __init__(self):
# set app default
self.app = FastAPI()
# set cors
if configs.BACKEND_CORS_ORIGINS:
self.app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:3000"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# set routes
@self.app.get("/")
def root():
return "service is working"
self.app.include_router(api.router, prefix=configs.API_V1_STR)
app_creator = AppCreator()
app = app_creator.app
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=30000)