Skip to content

Commit

Permalink
Corse allow methods in env options. #683
Browse files Browse the repository at this point in the history
  • Loading branch information
ubi15 committed Aug 11, 2023
1 parent ff66d5d commit a02cdd2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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(",")]

0 comments on commit a02cdd2

Please sign in to comment.