-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
61 lines (51 loc) · 1.55 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
50
51
52
53
54
55
56
57
58
59
60
61
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from motor.motor_asyncio import AsyncIOMotorClient
from beanie import init_beanie
from app.api.api_v1.router import api_v1_router
from app.core.config import settings
from app.system_logs.system_logs import CheckSystemLogs
# Databases
from app.models.user_models.user_model import UserModel
from app.models.todo_models.todo_model import TodoModel
# FastAPI App
app = FastAPI(
title=settings.PROJECT_NAME,
openapi_url=f"{settings.API_V1_STR}/openapi.json",
)
# [...]
app.add_middleware(
CORSMiddleware,
allow_origins=settings.BACKEND_CORS_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.on_event("startup")
async def app_init():
"""
initialize application services
"""
print(f"initialize f{settings.MONGO_CONNECTION_STRING}")
db_client = AsyncIOMotorClient(settings.MONGO_CONNECTION_STRING).fastapitemplate
await init_beanie(
database=db_client,
document_models=[
UserModel,
TodoModel,
]
)
print("initialize application services")
CheckSystemLogs.pass_logs("Initialize application services", log_level=2)
@app.get("/")
async def read_root():
"""
:return:
"""
return {
"Welcome to": "Python FastAPI Framework with Mongodb Scaffold Template",
"Software Engineer": "Tayyab Mughal",
"Github": "https://github.com/tayyabmughal676"
}
# Including the API V1 Routes
app.include_router(api_v1_router, prefix="/api/v1")