Skip to content

Commit

Permalink
Merge pull request #983 from lucapiccinelli/develop
Browse files Browse the repository at this point in the history
Environment variable to disable CORS middleware
  • Loading branch information
pieroit authored Dec 9, 2024
2 parents 2fdf311 + 5d664c1 commit 599bfbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions core/cat/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_supported_env_variables():
"CCAT_JWT_EXPIRE_MINUTES": str(60 * 24), # JWT expires after 1 day
"CCAT_HTTPS_PROXY_MODE": False,
"CCAT_CORS_FORWARDED_ALLOW_IPS": "*",
"CCAT_CORS_ENABLED": "true"
}


Expand Down
20 changes: 11 additions & 9 deletions core/cat/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ def custom_generate_unique_id(route: APIRoute):
)

# Configures the CORS middleware for the FastAPI app
cors_allowed_origins_str = get_env("CCAT_CORS_ALLOWED_ORIGINS")
origins = cors_allowed_origins_str.split(",") if cors_allowed_origins_str else ["*"]
cheshire_cat_api.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
cors_enabled = get_env("CCAT_CORS_ENABLED")
if cors_enabled == "true":
cors_allowed_origins_str = get_env("CCAT_CORS_ALLOWED_ORIGINS")
origins = cors_allowed_origins_str.split(",") if cors_allowed_origins_str else ["*"]
cheshire_cat_api.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

# Add routers to the middleware stack.
cheshire_cat_api.include_router(base.router, tags=["Home"])
Expand Down

0 comments on commit 599bfbc

Please sign in to comment.