feat: 跨域设置
This commit is contained in:
@@ -9,6 +9,7 @@ class EnvSettings(BaseSettings):
|
||||
llm_key_deepseek: str = Field(..., env="LLM_KEY_DEEPSEEK")
|
||||
|
||||
server_port: int = Field(..., env="SERVER_PORT")
|
||||
server_enable_cors: bool = Field(..., env="SERVER_ENABLE_CORS")
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
|
||||
+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