# -*- coding: utf-8 -*- import logging from pathlib import Path import uvicorn from fastapi import FastAPI from loguru import logger from app.api.routers import targets, equipment, space, item, user, bluetooth, devices from app.core.config import settings from app.core.events import create_start_app_handler from app.core.logger import InterceptHandler from app.db.session import Base, engine Base.metadata.create_all(bind=engine) logging.getLogger().handlers = [InterceptHandler()] logger.add(Path(settings.LOGS_DIR, 'env_fastapi.log'), level='INFO', rotation='00:00', encoding='utf-8') def get_application() -> FastAPI: application = FastAPI(title=settings.PROJECT_NAME, root_path='/env-py') application.add_event_handler('startup', create_start_app_handler()) 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']) application.include_router(item.router, prefix='/items', tags=['items']) application.include_router(user.router, prefix='/users', tags=['users']) application.include_router(bluetooth.router, prefix='/bluetooth', tags=['bluetooth']) application.include_router(devices.router, prefix='/devices', tags=['devices']) return application app = get_application() if __name__ == '__main__': uvicorn.run(app, host='0.0.0.0', port=8000)