Skip to content

Commit 75079c3

Browse files
authored
Merge pull request #424 from truefoundry/cj_configurable_cors
Allow configuring cors settings
2 parents 431d682 + 4cbb992 commit 75079c3

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

backend/server/app.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ async def restart_pool():
6262
lifespan=_process_pool_lifespan_manager,
6363
)
6464

65-
app.add_middleware(
66-
CORSMiddleware,
67-
allow_origins=["*"],
68-
allow_credentials=True,
69-
allow_methods=["*"],
70-
allow_headers=["*"],
71-
)
65+
66+
if settings.ALLOW_CORS:
67+
app.add_middleware(
68+
CORSMiddleware,
69+
**settings.CORS_CONFIG,
70+
)
7271

7372

7473
@app.exception_handler(Exception)

backend/settings.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from typing import Any, Dict
33

4-
from pydantic import ConfigDict, model_validator
4+
from pydantic import ConfigDict, Field, model_validator
55
from pydantic_settings import BaseSettings
66

77
from backend.types import MetadataStoreConfig, VectorDBConfig
@@ -31,6 +31,15 @@ class Settings(BaseSettings):
3131
LOCAL_DATA_DIRECTORY: str = os.path.abspath(
3232
os.path.join(os.path.dirname(os.path.dirname(__file__)), "user_data")
3333
)
34+
ALLOW_CORS: bool = False
35+
CORS_CONFIG: Dict[str, Any] = Field(
36+
default_factory=lambda: {
37+
"allow_origins": ["*"],
38+
"allow_credentials": False,
39+
"allow_methods": ["*"],
40+
"allow_headers": ["*"],
41+
}
42+
)
3443

3544
@model_validator(mode="before")
3645
@classmethod

truefoundry.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ components:
7474
UNSTRUCTURED_IO_URL: http://cas-unstructured-io.cognita-internal.svc.cluster.local:8000
7575
UNSTRUCTURED_IO_API_KEY: tfy-secret://internal:cognita:UNSTRUCTURED_IO_API_KEY
7676
BRAVE_API_KEY: tfy-secret://internal:cognita:BRAVE_API_KEY
77+
ALLOW_CORS: "true"
7778
type: service
7879
image:
7980
type: build

0 commit comments

Comments
 (0)