Coverage for src/kwai/app.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that creates a FastAPI application for the API and Frontend.""" 

2 

3from contextlib import asynccontextmanager 

4 

5from fastapi import FastAPI 

6from loguru import logger 

7 

8from kwai.api.app import create_api 

9from kwai.frontend.app import create_frontend 

10 

11 

12APP_NAME = "kwai" 

13 

14 

15@asynccontextmanager 

16async def lifespan(app: FastAPI): 

17 """Log the start/stop of the application.""" 

18 logger.info(f"{APP_NAME} is starting") 

19 yield 

20 logger.warning(f"{APP_NAME} has ended!") 

21 

22 

23def create_app() -> FastAPI: 

24 """Create the FastAPI application for API and frontend.""" 

25 main_app = FastAPI(title=APP_NAME, lifespan=lifespan) 

26 

27 api_app = create_api() 

28 main_app.mount("/api", api_app) 

29 

30 frontend_app = create_frontend() 

31 main_app.mount("/", frontend_app) 

32 

33 return main_app