-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
72 lines (53 loc) · 2.47 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
62
63
64
65
66
67
68
69
70
71
72
from fastapi import FastAPI
from mongoengine.connection import disconnect_all
from starlette.middleware.cors import CORSMiddleware
from config.config_loader import settings
from dbConnectionManager.db_session import platform_db_connection_instance, accounts_db_connection_instance
from routers.all_routes import malliva_routers, sub_malliva_routers, malliva_index_routers
import logging
logging.basicConfig(level=settings.LOG_LEVEL)
logger = logging.getLogger(__name__)
# initialize FastAPI
malliva_api = FastAPI(title=settings.PROJECT_NAME, # root_path=settings.API_V1_STR,
description=settings.DESCRIPTION,
openapi_url=f"{settings.API_V1_STR + settings.OPENAPI_URL}",
docs_url=f"{settings.API_V1_STR}/docs",
version="1.0", debug=settings.DEBUG)
@ malliva_api.on_event("startup")
async def startup():
logger.info("start up tasks running")
# initiallize database connection settings
await platform_db_connection_instance.initiate_db_connection()
await accounts_db_connection_instance.initiate_db_connection()
@ malliva_api.on_event("shutdown")
async def shutdown():
disconnect_all()
# import other routes
malliva_api.include_router(malliva_routers, prefix=settings.API_V1_STR)
malliva_api.include_router(malliva_index_routers)
# malliva_routers.include_router(
# admin.router,
# prefix="/admin",
# tags=["admin"],
# dependencies=[Depends(get_token_header)],
# responses={418: {"description": "I'm a teapot"}},
# )
# ___________________________________________________________________________
sub_malliva_api = FastAPI(title=settings.ACCOUNT_PROJECT_NAME,
description=settings.ACCOUNT_DESCRIPTION, # root_path=settings.API_V1_STR,
openapi_url=f"{settings.API_V1_STR + settings.OPENAPI_URL}",
docs_url=f"{settings.API_V1_STR}/docs",
version="1.0", debug=settings.DEBUG)
sub_malliva_api.include_router(sub_malliva_routers, prefix=settings.API_V1_STR)
malliva_api.mount("/maccounts", sub_malliva_api)
# Set all CORS enabled origins
if settings.BACKEND_CORS_ORIGINS:
print("Cors settings loaded")
malliva_api.add_middleware(
CORSMiddleware,
allow_origins=[str(origin)
for origin in settings.BACKEND_CORS_ORIGINS],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"])
malliva_api.middleware("http")