zhanghui пре 1 месец
родитељ
комит
ad886299be
1 измењених фајлова са 14 додато и 2 уклоњено
  1. 14 2
      main.py

+ 14 - 2
main.py

@@ -13,7 +13,19 @@ from flask import Flask
 
 # 初始化 Flask 应用
 app = Flask(__name__)
-
+# 配置 CORS 中间件 - 允许跨域请求
+app.add_middleware(
+    CORSMiddleware,
+    allow_origins=[
+        "http://localhost:5173",  # Vue 开发服务器
+        "http://127.0.0.1:5173",  # Vue 开发服务器(另一个地址)
+        "http://192.168.124.25:5173",  # 局域网 Vue 地址
+        "*",  # 允许所有来源(生产环境建议限制具体域名)
+    ],
+    allow_credentials=True,
+    allow_methods=["*"],  # 允许所有 HTTP 方法 (GET, POST, PUT, DELETE 等)
+    allow_headers=["*"],  # 允许所有请求头
+)
 # 批量注册所有路由
 for router in all_routers:
     app.include_router(router)
@@ -30,7 +42,6 @@ def test_env():
 async def health_check():
     return {"status": "healthy", "service": "multi_domain_intent_recognition"}
 
-
 # ========== 缓存管理 API ==========
 @app.post("/api/v1/cache/clear")
 async def clear_all_caches():
@@ -76,6 +87,7 @@ async def clear_all_caches():
 
         return {
             "status": "success",
+            "code": 200,
             "message": "所有缓存已清除",
             "timestamp": time.time()
         }