gavanduffy commited on
Commit ·
97fe226
1
Parent(s): 65fb15f
Fix CORS config: use str type to avoid pydantic-settings JSON parsing; fallback gracefully for env var format issues
Browse files- .env +1 -1
- Dockerfile +1 -1
- api/src/core/config.py +10 -8
- api/src/main.py +1 -1
.env
CHANGED
|
@@ -8,7 +8,7 @@ NEUTTS_DEFAULT_VOICE=jo
|
|
| 8 |
NEUTTS_SAMPLE_RATE=24000
|
| 9 |
NEUTTS_DEFAULT_RESPONSE_FORMAT=mp3
|
| 10 |
NEUTTS_CORS_ENABLED=true
|
| 11 |
-
NEUTTS_CORS_ORIGINS=
|
| 12 |
NEUTTS_LOG_LEVEL=-info
|
| 13 |
NEUTTS_MAX_INFERENCE_WORKERS=4
|
| 14 |
NEUTTS_ALLOW_VOICE_UPLOAD=true
|
|
|
|
| 8 |
NEUTTS_SAMPLE_RATE=24000
|
| 9 |
NEUTTS_DEFAULT_RESPONSE_FORMAT=mp3
|
| 10 |
NEUTTS_CORS_ENABLED=true
|
| 11 |
+
NEUTTS_CORS_ORIGINS=*
|
| 12 |
NEUTTS_LOG_LEVEL=-info
|
| 13 |
NEUTTS_MAX_INFERENCE_WORKERS=4
|
| 14 |
NEUTTS_ALLOW_VOICE_UPLOAD=true
|
Dockerfile
CHANGED
|
@@ -22,7 +22,7 @@ ENV NEUTTS_DEFAULT_CODEC_DEVICE=cpu
|
|
| 22 |
ENV NEUTTS_DEFAULT_VOICE=jo
|
| 23 |
ENV NEUTTS_LOG_LEVEL=INFO
|
| 24 |
ENV NEUTTS_CORS_ENABLED=true
|
| 25 |
-
ENV NEUTTS_CORS_ORIGINS=
|
| 26 |
|
| 27 |
RUN pip install --no-cache-dir uv
|
| 28 |
|
|
|
|
| 22 |
ENV NEUTTS_DEFAULT_VOICE=jo
|
| 23 |
ENV NEUTTS_LOG_LEVEL=INFO
|
| 24 |
ENV NEUTTS_CORS_ENABLED=true
|
| 25 |
+
ENV NEUTTS_CORS_ORIGINS=*
|
| 26 |
|
| 27 |
RUN pip install --no-cache-dir uv
|
| 28 |
|
api/src/core/config.py
CHANGED
|
@@ -3,7 +3,6 @@ from __future__ import annotations
|
|
| 3 |
import json
|
| 4 |
from typing import Literal
|
| 5 |
|
| 6 |
-
from pydantic import Field, field_validator
|
| 7 |
from pydantic_settings import BaseSettings
|
| 8 |
|
| 9 |
|
|
@@ -29,7 +28,7 @@ class Settings(BaseSettings):
|
|
| 29 |
|
| 30 |
# CORS
|
| 31 |
cors_enabled: bool = True
|
| 32 |
-
cors_origins:
|
| 33 |
|
| 34 |
# Logging
|
| 35 |
log_level: str = "INFO"
|
|
@@ -40,12 +39,15 @@ class Settings(BaseSettings):
|
|
| 40 |
# Voice Upload
|
| 41 |
allow_voice_upload: bool = True
|
| 42 |
|
| 43 |
-
@
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
@property
|
| 51 |
def default_models_list(self) -> list[str]:
|
|
|
|
| 3 |
import json
|
| 4 |
from typing import Literal
|
| 5 |
|
|
|
|
| 6 |
from pydantic_settings import BaseSettings
|
| 7 |
|
| 8 |
|
|
|
|
| 28 |
|
| 29 |
# CORS
|
| 30 |
cors_enabled: bool = True
|
| 31 |
+
cors_origins: str = "*"
|
| 32 |
|
| 33 |
# Logging
|
| 34 |
log_level: str = "INFO"
|
|
|
|
| 39 |
# Voice Upload
|
| 40 |
allow_voice_upload: bool = True
|
| 41 |
|
| 42 |
+
@property
|
| 43 |
+
def cors_origins_list(self) -> list[str]:
|
| 44 |
+
try:
|
| 45 |
+
parsed = json.loads(self.cors_origins)
|
| 46 |
+
if isinstance(parsed, list):
|
| 47 |
+
return parsed
|
| 48 |
+
except json.JSONDecodeError:
|
| 49 |
+
pass
|
| 50 |
+
return [o.strip() for o in self.cors_origins.split(",") if o.strip()]
|
| 51 |
|
| 52 |
@property
|
| 53 |
def default_models_list(self) -> list[str]:
|
api/src/main.py
CHANGED
|
@@ -89,7 +89,7 @@ app = FastAPI(
|
|
| 89 |
if settings.cors_enabled:
|
| 90 |
app.add_middleware(
|
| 91 |
CORSMiddleware,
|
| 92 |
-
allow_origins=settings.
|
| 93 |
allow_credentials=True,
|
| 94 |
allow_methods=["*"],
|
| 95 |
allow_headers=["*"],
|
|
|
|
| 89 |
if settings.cors_enabled:
|
| 90 |
app.add_middleware(
|
| 91 |
CORSMiddleware,
|
| 92 |
+
allow_origins=settings.cors_origins_list,
|
| 93 |
allow_credentials=True,
|
| 94 |
allow_methods=["*"],
|
| 95 |
allow_headers=["*"],
|