Skip to content

Commit 5ffde08

Browse files
authored
Merge pull request #198 from ecmwf-projects/COPDS-1878-allow-origins
Allow CORS by default
2 parents ca64804 + 18b17f2 commit 5ffde08

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

cads_processing_api_service/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class Settings(pydantic_settings.BaseSettings):
3737
profiles_service: str = "profiles-api"
3838
profiles_api_service_port: int = 8000
3939

40+
allow_cors: bool = True
41+
4042
default_cache_control: str = "max-age=2"
4143
default_vary: str = "PRIVATE-TOKEN, Authorization"
4244
public_cache_control: str = "public, max-age=60"

cads_processing_api_service/main.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# limitations under the License
1616

1717
import logging
18-
import os
1918
import uuid
2019
from contextlib import asynccontextmanager
2120
from typing import Any, AsyncGenerator, Awaitable, Callable, Mapping, MutableMapping
@@ -27,7 +26,15 @@
2726
import starlette_exporter
2827
import structlog
2928

30-
from . import clients, constraints, costing, exceptions, middlewares, translators
29+
from . import (
30+
clients,
31+
config,
32+
constraints,
33+
costing,
34+
exceptions,
35+
middlewares,
36+
translators,
37+
)
3138

3239

3340
def add_user_request_flag(
@@ -86,7 +93,7 @@ async def initialize_logger(
8693
return response
8794

8895

89-
if os.environ.get("DEBUG", "0") == "1":
96+
if config.ensure_settings().allow_cors:
9097
app.add_middleware(
9198
fastapi.middleware.cors.CORSMiddleware,
9299
allow_origins=["*"],

0 commit comments

Comments
 (0)