-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (37 loc) · 1.21 KB
/
Copy pathmain.py
File metadata and controls
52 lines (37 loc) · 1.21 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
import uvicorn
from fastapi.responses import JSONResponse
from fastapi_offline import FastAPIOffline as FastAPI
from auth.routers import router as auth_router
from core.base.expections import CustomException
from core.config import settings
from infrastructure.sqlalchemy.utiles import init_models
from users.router import router as users_router
async def create_models(app: FastAPI):
await init_models()
yield
app = FastAPI(lifespan=create_models)
app.include_router(router=users_router, tags=["Users"])
app.include_router(router=auth_router, tags=["Auth"])
@app.exception_handler(CustomException)
async def custom_exception_handler(request, exc: CustomException):
return JSONResponse(
status_code=exc.code,
content={
"success": False,
"error": {
"code": exc.error_code,
"message": exc.message,
"status_code": exc.code,
},
},
)
print("database url is ", settings.DATABASE_URL)
def main():
uvicorn.run(
"main:app",
host=settings.HOST,
port=settings.POST,
reload=True if settings.ENVIRONMENT == "development" else False,
)
if __name__ == "__main__":
main()