From 9d53f1b8f74727db6648ac63f48c2749b1e1040d Mon Sep 17 00:00:00 2001 From: Paul Tomasula <31142705+ptomasula@users.noreply.github.com> Date: Fri, 19 Jul 2024 12:12:57 -0400 Subject: [PATCH] Fix for Starlette CORS (#1741) * 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 --- pygeoapi/starlette_app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pygeoapi/starlette_app.py b/pygeoapi/starlette_app.py index b2ddf4858..9f4e33f79 100644 --- a/pygeoapi/starlette_app.py +++ b/pygeoapi/starlette_app.py @@ -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'])