diff --git a/app/webservice.py b/app/webservice.py index 5391afe..629d80d 100644 --- a/app/webservice.py +++ b/app/webservice.py @@ -13,6 +13,7 @@ from fastapi.responses import RedirectResponse, StreamingResponse from fastapi.staticfiles import StaticFiles from whisper import tokenizer +from fastapi.middleware.cors import CORSMiddleware ASR_ENGINE = os.getenv("ASR_ENGINE", "openai_whisper") if ASR_ENGINE == "faster_whisper": @@ -33,6 +34,14 @@ license_info={"name": "MIT License", "url": projectMetadata["License"]}, ) +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], # 允许所有源,生产环境建议设置具体的源 + allow_credentials=True, + allow_methods=["*"], # 允许所有方法 + allow_headers=["*"], # 允许所有请求头 +) + assets_path = os.getcwd() + "/swagger-ui-assets" if path.exists(assets_path + "/swagger-ui.css") and path.exists(assets_path + "/swagger-ui-bundle.js"): app.mount("/assets", StaticFiles(directory=assets_path), name="static")