Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corse allow methods in env options. #683 #684

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The default application can be customized using environment variables defined in

- `NAME` (str): name of the application. Defaults to `titiler`.
- `CORS_ORIGINS` (str, `,` delimited origins): allowed CORS origin. Defaults to `*`.
- `CORS_ALLOW_METHODS` (str, `,` delimited methods): allowed CORS methods. Defaults to `GET`.
- `CACHECONTROL` (str): Cache control header to add to responses. Defaults to `"public, max-age=3600"`.
- `ROOT_PATH` (str): path behind proxy.
- `DEBUG` (str): adds `LoggerMiddleware` and `TotalTimeMiddleware` in the middleware stack.
Expand Down
2 changes: 1 addition & 1 deletion src/titiler/application/titiler/application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
CORSMiddleware,
allow_origins=api_settings.cors_origins,
allow_credentials=True,
allow_methods=["GET"],
allow_methods=api_settings.cors_allow_methods,
allow_headers=["*"],
)

Expand Down
6 changes: 6 additions & 0 deletions src/titiler/application/titiler/application/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ApiSettings(BaseSettings):

name: str = "TiTiler"
cors_origins: str = "*"
cors_allow_methods: str = "GET"
cachecontrol: str = "public, max-age=3600"
root_path: str = ""
debug: bool = False
Expand All @@ -25,3 +26,8 @@ class ApiSettings(BaseSettings):
def parse_cors_origin(cls, v):
"""Parse CORS origins."""
return [origin.strip() for origin in v.split(",")]

@field_validator("cors_allow_methods")
def parse_cors_allow_methods(cls, v):
"""Parse CORS allowed methods."""
return [method.strip().upper() for method in v.split(",")]