From 15fcb04368b8c7e5065f87a86650f216e9e2eae5 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Thu, 17 Jan 2019 09:10:00 +0100 Subject: [PATCH] Support OPTIONS method for all API endpoints --- flatisfy/web/app.py | 6 +++--- flatisfy/web/routes/api.py | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/flatisfy/web/app.py b/flatisfy/web/app.py index a10e376..e78f2fb 100644 --- a/flatisfy/web/app.py +++ b/flatisfy/web/app.py @@ -101,10 +101,10 @@ def get_app(config): app.route("/api/v1/ics/visits.ics", ["GET", "OPTIONS"], api_routes.ics_feed_v1) - app.route("/api/v1/search", "POST", api_routes.search_v1) + app.route("/api/v1/search", ["POST", "OPTIONS"], api_routes.search_v1) - app.route("/api/v1/opendata", "GET", api_routes.opendata_index_v1) - app.route("/api/v1/opendata/postal_codes", "GET", + app.route("/api/v1/opendata", ["GET", "OPTIONS"], api_routes.opendata_index_v1) + app.route("/api/v1/opendata/postal_codes", ["GET", "OPTIONS"], api_routes.opendata_postal_codes_v1) app.route("/api/v1/metadata", ["GET", "OPTIONS"], api_routes.metadata_v1) diff --git a/flatisfy/web/routes/api.py b/flatisfy/web/routes/api.py index 101a821..ca897fc 100644 --- a/flatisfy/web/routes/api.py +++ b/flatisfy/web/routes/api.py @@ -439,6 +439,10 @@ def opendata_index_v1(): GET /api/v1/opendata """ + if bottle.request.method == 'OPTIONS': + # CORS + return {} + return { "postal_codes": "/api/v1/opendata/postal_codes" }