添加跨域

This commit is contained in:
shikong 2023-05-31 14:31:13 +08:00
parent 2860dfb5ef
commit 7d19573f85
3 changed files with 14 additions and 7 deletions

View File

@ -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="题目列表")

View File

@ -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")

12
main.py
View File

@ -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)