main.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. import uvicorn
  4. from fastapi import FastAPI
  5. from app.api.errors.iot import MissingIOTDataError, missing_data_exception_handler
  6. from app.api.routers import (
  7. algorithms,
  8. targets,
  9. space,
  10. bluetooth,
  11. devices,
  12. positioning,
  13. )
  14. from app.api.routers.model_path import early_start
  15. from app.core.config import settings
  16. from app.core.events import create_start_app_handler
  17. from app.core.logger import InterceptHandler
  18. from app.db.session import Base, engine
  19. Base.metadata.create_all(bind=engine)
  20. logging.getLogger().handlers = [InterceptHandler()]
  21. def get_application() -> FastAPI:
  22. application = FastAPI(title=settings.PROJECT_NAME)
  23. application.add_event_handler("startup", create_start_app_handler())
  24. application.include_router(algorithms.router, prefix="/algo", tags=["Algorithms"])
  25. application.include_router(bluetooth.router, prefix="/bluetooth", tags=["BLE"])
  26. application.include_router(devices.router, prefix="/devices", tags=["Devices"])
  27. application.include_router(early_start.router, prefix="/model-path", tags=["Model Path"])
  28. application.include_router(positioning.router, prefix="/positioning-service", tags=["Positioning Service"])
  29. application.include_router(space.router, prefix="/room", tags=["Spaces"])
  30. application.include_router(targets.router, prefix="/target", tags=["Targets"])
  31. application.add_exception_handler(MissingIOTDataError, missing_data_exception_handler)
  32. return application
  33. app = get_application()
  34. if __name__ == "__main__":
  35. uvicorn.run(app, host="0.0.0.0", port=8000)