-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
42 lines (27 loc) · 947 Bytes
/
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
from core.config import settings
from database.base import Base
from database.session import engine
from database.utils import check_db_connected
from database.utils import check_db_disconnected
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from webapps.base import api_router as web_app_router
def include_router(app):
app.include_router(web_app_router)
def configure_static(app):
app.mount("/static", StaticFiles(directory="static"), name="static")
def create_tables():
Base.metadata.create_all(bind=engine)
def start_application():
app = FastAPI(title=settings.PROJECT_NAME, version=settings.PROJECT_VERSION)
include_router(app)
configure_static(app)
create_tables()
return app
app = start_application()
@app.on_event("startup")
async def app_startup():
await check_db_connected()
@app.on_event("shutdown")
async def app_shutdown():
await check_db_disconnected()