From e2bb66f5f17844957a1e3ec2dfa829bf6c8f18d7 Mon Sep 17 00:00:00 2001 From: sovanna Date: Tue, 14 Apr 2020 14:19:30 +0900 Subject: [PATCH] feat(issue22/server-flask): Adds extra config for CORS --- server/app/__init__.py | 4 +++- server/config.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/server/app/__init__.py b/server/app/__init__.py index 406c603..c159c56 100644 --- a/server/app/__init__.py +++ b/server/app/__init__.py @@ -23,7 +23,9 @@ def create_app(cfg=config): CORS( app, resources={r'/api/*': { - 'origins': '*', + 'methods': ['POST', 'OPTIONS'], + 'allow_origins': app.config['CORS_ALLOWED_ORIGINS'].split(','), + 'allow_headers': app.config['CORS_ALLOWED_HEADERS'].split(','), }}) return app diff --git a/server/config.py b/server/config.py index db7a238..4af58e5 100644 --- a/server/config.py +++ b/server/config.py @@ -16,3 +16,6 @@ MAIL_USERNAME = getenv("FLASK_MAIL_USERNAME") MAIL_PASSWORD = getenv("FLASK_MAIL_PASSWORD") MAIL_RECIPIENT = getenv("FLASK_MAIL_RECIPIENT") + +CORS_ALLOWED_ORIGINS = getenv("FLASK_CORS_ORIGINS") +CORS_ALLOWED_HEADERS = getenv("FLASK_CORS_ALLOW_HEADERS")