-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathapp.py
37 lines (25 loc) · 816 Bytes
/
app.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
from contextlib import asynccontextmanager
from fastapi import FastAPI
from api.config import Settings
from api.database import create_db_and_tables
from api.public import api as public_api
from api.utils.logger import logger_config
from api.utils.mock_data_generator import create_heroes_and_teams
logger = logger_config(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
create_db_and_tables()
create_heroes_and_teams()
logger.info("startup: triggered")
yield
logger.info("shutdown: triggered")
def create_app(settings: Settings):
app = FastAPI(
title=settings.PROJECT_NAME,
version=settings.VERSION,
docs_url="/",
description=settings.DESCRIPTION,
lifespan=lifespan,
)
app.include_router(public_api)
return app