main.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 targets, equipment, space, item, user, bluetooth
  8. from app.core.config import settings
  9. from app.core.events import create_start_app_handler
  10. from app.core.logger import InterceptHandler
  11. from app.db.session import Base, engine
  12. Base.metadata.create_all(bind=engine)
  13. logging.getLogger().handlers = [InterceptHandler()]
  14. logger.add(Path(settings.LOGS_DIR, 'env_fastapi.log'), level='INFO', rotation='00:00', encoding='utf-8')
  15. def get_application() -> FastAPI:
  16. application = FastAPI(title=settings.PROJECT_NAME)
  17. application.add_event_handler('startup', create_start_app_handler())
  18. application.include_router(equipment.router, prefix='/equip', tags=['equipment'])
  19. application.include_router(space.router, prefix='/room', tags=['spaces'])
  20. application.include_router(targets.router, prefix='/target', tags=['targets'])
  21. application.include_router(item.router, prefix='/items', tags=['items'])
  22. application.include_router(user.router, prefix='/users', tags=['users'])
  23. application.include_router(bluetooth.router, prefix='/bluetooth', tags=['bluetooth'])
  24. return application
  25. app = get_application()
  26. if __name__ == '__main__':
  27. uvicorn.run(app, host='0.0.0.0', port=8000)