import os.path import logger import uvicorn from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.staticfiles import StaticFiles from handler import car, health # 禁用 redoc app = FastAPI(docs_url="/docs", redoc_url=None) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(health.router) app.include_router(car.router) frontend = os.path.join(os.path.dirname(__file__), "frontend") app.mount("/", StaticFiles(directory=frontend, html=True)) @app.on_event("startup") async def startup(): logger.logger.info("服务启动") @app.on_event("shutdown") async def shutdown(): logger.logger.info("服务关闭") if __name__ == '__main__': uvicorn.run("main:app", host="0.0.0.0", port=5000, reload=True)