main.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. from pathlib import Path
  4. import uvicorn
  5. from fastapi import FastAPI
  6. from loguru import logger
  7. from app.api.routers import algorithms, targets, equipment, space, item, user, bluetooth, devices, nlp, positioning
  8. from app.api.routers.model_path import early_start
  9. from app.core.config import settings
  10. from app.core.events import create_start_app_handler
  11. from app.core.logger import InterceptHandler
  12. from app.db.session import Base, engine
  13. Base.metadata.create_all(bind=engine)
  14. logging.getLogger().handlers = [InterceptHandler()]
  15. logger.add(Path(settings.LOGS_DIR, 'env_fastapi.log'), level='INFO', rotation='00:00', encoding='utf-8')
  16. def get_application() -> FastAPI:
  17. application = FastAPI(title=settings.PROJECT_NAME, root_path='/env-py')
  18. application.add_event_handler('startup', create_start_app_handler())
  19. application.include_router(algorithms.router, prefix='/algo', tags=['Algorithms'])
  20. application.include_router(bluetooth.router, prefix='/bluetooth', tags=['BLE'])
  21. application.include_router(devices.router, prefix='/devices', tags=['Devices'])
  22. application.include_router(early_start.router, prefix='/model-path', tags=['Model Path'])
  23. application.include_router(equipment.router, prefix='/equip', tags=['Equipment'])
  24. application.include_router(item.router, prefix='/items', tags=['Items'])
  25. application.include_router(nlp.router, prefix='/nlp-service', tags=['NLP'])
  26. application.include_router(positioning.router, prefix='/positioning-service', tags=['Positioning Service'])
  27. application.include_router(space.router, prefix='/room', tags=['Spaces'])
  28. application.include_router(targets.router, prefix='/target', tags=['Targets'])
  29. application.include_router(user.router, prefix='/users', tags=['Users'])
  30. return application
  31. app = get_application()
  32. if __name__ == '__main__':
  33. uvicorn.run(app, host='0.0.0.0', port=8000)