

update cors pr
@34ceec62b0e441830dbdc330c7f21b8170d83066
--- faster_whisper_server/config.py
+++ faster_whisper_server/config.py
... | ... | @@ -170,6 +170,13 @@ |
170 | 170 |
log_level: str = "info" |
171 | 171 |
host: str = Field(alias="UVICORN_HOST", default="0.0.0.0") |
172 | 172 |
port: int = Field(alias="UVICORN_PORT", default=8000) |
173 |
+ allow_origins: list[str] | None = None |
|
174 |
+ """ |
|
175 |
+ https://docs.pydantic.dev/latest/concepts/pydantic_settings/#parsing-environment-variable-values |
|
176 |
+ Usage: |
|
177 |
+ `export ALLOW_ORIGINS='["http://localhost:3000", "http://localhost:3001"]'` |
|
178 |
+ `export ALLOW_ORIGINS='["*"]'` |
|
179 |
+ """ |
|
173 | 180 |
|
174 | 181 |
enable_ui: bool = True |
175 | 182 |
""" |
--- faster_whisper_server/main.py
+++ faster_whisper_server/main.py
... | ... | @@ -17,6 +17,7 @@ |
17 | 17 |
WebSocket, |
18 | 18 |
WebSocketDisconnect, |
19 | 19 |
) |
20 |
+from fastapi.middleware.cors import CORSMiddleware |
|
20 | 21 |
from fastapi.responses import StreamingResponse |
21 | 22 |
from fastapi.websockets import WebSocketState |
22 | 23 |
from faster_whisper import WhisperModel |
... | ... | @@ -77,16 +78,14 @@ |
77 | 78 |
|
78 | 79 |
app = FastAPI() |
79 | 80 |
|
80 |
-cors_origins = os.environ.get("CORS_ORIGINS", "").split(",") |
|
81 |
-if cors_origins: |
|
81 |
+if config.allow_origins is not None: |
|
82 | 82 |
app.add_middleware( |
83 | 83 |
CORSMiddleware, |
84 |
- allow_origins=cors_origins, |
|
84 |
+ allow_origins=config.allow_origins, |
|
85 | 85 |
allow_credentials=True, |
86 | 86 |
allow_methods=["*"], |
87 | 87 |
allow_headers=["*"], |
88 | 88 |
) |
89 |
- |
|
90 | 89 |
|
91 | 90 |
|
92 | 91 |
@app.get("/health") |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?