-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (45 loc) · 1.38 KB
/
main.py
File metadata and controls
60 lines (45 loc) · 1.38 KB
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
59
60
import uvicorn
from fastapi import FastAPI
from fastapi.middleware import Middleware
from fastapi.middleware.cors import CORSMiddleware
from src.api.api import api_router
from src.configs.settings import settings
from src.configs.version import BACKEND_VERSION
from src.core.db.session import init_db
from src.core.middlewares.context_middleware import ContextMiddleware
def init_routers(app: FastAPI) -> None:
app.include_router(api_router, prefix=settings.API_PREFIX)
def make_middleware() -> list[Middleware]:
middleware = [
Middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["Access-Token", "Authorization", "Content-Deposition"],
),
]
return middleware
def create_app():
# Initialize database
init_db()
app = FastAPI(
title="NetsPresso Training Studio",
version=BACKEND_VERSION,
middleware=make_middleware(),
)
init_routers(app=app)
app.add_middleware(ContextMiddleware)
return app
app = create_app()
@app.get("/")
def healthcheck():
return {"message": "Hello NetsPresso Training Studio!"}
if __name__ == "__main__":
uvicorn.run(
app=app,
host="0.0.0.0",
port=settings.SERVER_PORT,
workers=settings.SERVER_WORKERS,
)