Skip to content

Commit

Permalink
Fix for Starlette CORS (#1741)
Browse files Browse the repository at this point in the history
* Fix for Starlette CORS

The Starlette app with setting cors=true enables all origins, but only permits requests with the GET method. The CORSMiddleware for Starlette requires specifying `allow_methods=['*']` to enable all common request methods.

* Add noqa to break line break

This line was flagged by flake 8 for being 81 characters. I think that this line it more readable as is rather than splitting up into multiple lines.

* Revise indentation on CORS middleware
  • Loading branch information
ptomasula authored Jul 19, 2024
1 parent 05a7de4 commit 9d53f1b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pygeoapi/starlette_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,11 @@ async def __call__(self, scope: Scope,
# CORS: optionally enable from config.
if CONFIG['server'].get('cors', False):
from starlette.middleware.cors import CORSMiddleware
APP.add_middleware(CORSMiddleware, allow_origins=['*'])
APP.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_methods=['*'],
)

try:
OGC_SCHEMAS_LOCATION = Path(CONFIG['server']['ogc_schemas_location'])
Expand Down

0 comments on commit 9d53f1b

Please sign in to comment.