feat: 跨域设置
This commit is contained in:
+10
-1
@@ -6,6 +6,7 @@ from fastapi.openapi.docs import get_swagger_ui_oauth2_redirect_html, get_redoc_
|
||||
from fastapi.responses import RedirectResponse
|
||||
from langchain.chat_models import init_chat_model
|
||||
from langserve import add_routes
|
||||
from starlette.middleware.cors import CORSMiddleware
|
||||
from starlette.staticfiles import StaticFiles
|
||||
|
||||
from app.config.env import env
|
||||
@@ -32,4 +33,12 @@ app = FastAPI(
|
||||
for add_route_func in routes:
|
||||
add_route_func(app)
|
||||
|
||||
print("/*---------------------------------------main-------------------------------------------*/")
|
||||
if env.server_enable_cors:
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
expose_headers=["*"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user