|
@@ -7,26 +7,28 @@ import uvicorn
|
|
|
from fastapi import FastAPI
|
|
|
from loguru import logger
|
|
|
|
|
|
-from app.api.routers import targets, equipment, space, item
|
|
|
+from app.api.routers import targets, equipment, space
|
|
|
from app.core.config import settings
|
|
|
+from app.core.events import create_start_app_handler
|
|
|
from app.core.logger import InterceptHandler
|
|
|
|
|
|
logging.getLogger().handlers = [InterceptHandler()]
|
|
|
logger.add(Path(settings.LOGS_DIR, 'env_fastapi.log'), level='INFO', rotation='00:00', encoding='utf-8')
|
|
|
|
|
|
-app = FastAPI(title=settings.PROJECT_NAME)
|
|
|
|
|
|
-app.include_router(targets.router, prefix='/target', tags=['targets'])
|
|
|
-app.include_router(space.router, prefix='/room', tags=['spaces'])
|
|
|
-app.include_router(equipment.router, prefix='/equip', tags=['equipment'])
|
|
|
-app.include_router(item.router, prefix='/item', tags=['items'])
|
|
|
+def get_application() -> FastAPI:
|
|
|
+ application = FastAPI(title=settings.PROJECT_NAME)
|
|
|
|
|
|
+ application.add_event_handler('startup', create_start_app_handler())
|
|
|
|
|
|
-@app.get('/settings')
|
|
|
-async def info():
|
|
|
- return {
|
|
|
- 'logs_dir': settings
|
|
|
- }
|
|
|
+ application.include_router(equipment.router, prefix='/equip', tags=['equipment'])
|
|
|
+ application.include_router(space.router, prefix='/room', tags=['spaces'])
|
|
|
+ application.include_router(targets.router, prefix='/target', tags=['targets'])
|
|
|
+
|
|
|
+ return application
|
|
|
+
|
|
|
+
|
|
|
+app = get_application()
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|