diff --git a/handler/car.py b/handler/car.py index e3361fb..32ea668 100644 --- a/handler/car.py +++ b/handler/car.py @@ -1,15 +1,14 @@ +from fastapi import APIRouter, Depends from sqlalchemy.orm import Session import logger -from fastapi import APIRouter, Depends, Query - from db.mysql import database from model.car.dto.list import ListDto from orm.jiakaobaodian import JiaKaoBaoDian -from utils.common import response, strtobool +from utils.common import response from utils.model import model_list -router = APIRouter(tags=["Car"], prefix="/car") +router = APIRouter(tags=["Car"], prefix="/api/car") @router.post("/list", summary="题目列表") diff --git a/handler/health.py b/handler/health.py index 4c9a23e..32bdb6e 100644 --- a/handler/health.py +++ b/handler/health.py @@ -2,7 +2,7 @@ import logger from fastapi import APIRouter from utils.common import response -router = APIRouter(tags=["Health"]) +router = APIRouter(tags=["Health"], prefix="/api") @router.get("/health") diff --git a/main.py b/main.py index b47f710..5d7e1f4 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,20 @@ import logger import uvicorn -from fastapi import FastAPI - +from fastapi import FastAPI, APIRouter +from fastapi.middleware.cors import CORSMiddleware 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)