From 92ea6026f85e749a263a55c4c391fdf1fb7cdd89 Mon Sep 17 00:00:00 2001 From: AoXuan Date: Mon, 4 Aug 2025 02:22:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E8=B7=A8?= =?UTF-8?q?=E5=9F=9F=E8=B5=84=E6=BA=90=E5=85=B1=E4=BA=AB=20(CORS)=20?= =?UTF-8?q?=E4=B8=AD=E9=97=B4=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/api.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/api/api.py b/app/api/api.py index ba5d28b..5bd5f80 100644 --- a/app/api/api.py +++ b/app/api/api.py @@ -3,6 +3,7 @@ from pydantic import BaseModel, Field from typing import Dict, Any, List, Optional, Literal from datetime import datetime +from fastapi.middleware.cors import CORSMiddleware from app.core import Config, logger @@ -12,6 +13,14 @@ app = FastAPI( version="1.0.0", ) +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], # 允许所有域名跨域访问 + allow_credentials=True, + allow_methods=["*"], # 允许所有请求方法,如 GET、POST、PUT、DELETE + allow_headers=["*"], # 允许所有请求头 +) + # 此文件由ai生成 返回值非最终版本