Skip to content

Commit

Permalink
Merge pull request #198 from ecmwf-projects/COPDS-1878-allow-origins
Browse files Browse the repository at this point in the history
Allow CORS by default
  • Loading branch information
mcucchi9 authored Jul 17, 2024
2 parents ca64804 + 18b17f2 commit 5ffde08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cads_processing_api_service/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Settings(pydantic_settings.BaseSettings):
profiles_service: str = "profiles-api"
profiles_api_service_port: int = 8000

allow_cors: bool = True

default_cache_control: str = "max-age=2"
default_vary: str = "PRIVATE-TOKEN, Authorization"
public_cache_control: str = "public, max-age=60"
Expand Down
13 changes: 10 additions & 3 deletions cads_processing_api_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# limitations under the License

import logging
import os
import uuid
from contextlib import asynccontextmanager
from typing import Any, AsyncGenerator, Awaitable, Callable, Mapping, MutableMapping
Expand All @@ -27,7 +26,15 @@
import starlette_exporter
import structlog

from . import clients, constraints, costing, exceptions, middlewares, translators
from . import (
clients,
config,
constraints,
costing,
exceptions,
middlewares,
translators,
)


def add_user_request_flag(
Expand Down Expand Up @@ -86,7 +93,7 @@ async def initialize_logger(
return response


if os.environ.get("DEBUG", "0") == "1":
if config.ensure_settings().allow_cors:
app.add_middleware(
fastapi.middleware.cors.CORSMiddleware,
allow_origins=["*"],
Expand Down

0 comments on commit 5ffde08

Please sign in to comment.