-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
49 lines (38 loc) · 1.21 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
48
49
from env import appConfig as config
from fastapi import FastAPI,Request,Response,Depends
from fastapi.responses import JSONResponse
from db import engine,Base
from fastapi.middleware.cors import CORSMiddleware
from starlette_session import SessionMiddleware
from router import example
from exception import customException
app = FastAPI() if config.LIST_ENDPOINTS else FastAPI(openapi_url="")
#Create DB schema
Base.metadata.create_all(bind=engine)
#Session config
app.add_middleware(
SessionMiddleware,
secret_key = config.COOKIE_SECRET_KEY,
cookie_name = config.COOKIE_NAME,
max_age = config.COOKIE_MAX_AGE,
same_site = config.COOKIE_SAME_SITE,
domain = config.COOKIE_DOMAIN
)
#CORS config
app.add_middleware(
CORSMiddleware,
allow_origins=config.AUTH_DOMAINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
app.include_router(example.router,prefix="/api")
@app.get("/")
def root():
return 'Start building amazing applications !'
@app.exception_handler(customException)
async def exception_handler(request: Request, exc: customException):
return JSONResponse(
status_code=exc.status_code,
content={"message":exc.message},
)