Skip to content

Commit

Permalink
Add Cors support in the app (#119)
Browse files Browse the repository at this point in the history
* Add Cors support in the app

* Add Env var CORS_ENABLED
  • Loading branch information
PaschalisDim authored Mar 26, 2020
1 parent 7fe73c7 commit c360660
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion metadata_service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
from typing import Dict, Any # noqa: F401
from flask_cors import CORS

from flasgger import Swagger
from flask import Flask, Blueprint
Expand All @@ -22,13 +23,15 @@
UserFollowsAPI, UserOwnsAPI,
UserOwnAPI, UserReadsAPI)


# For customized flask use below arguments to override.
FLASK_APP_MODULE_NAME = os.getenv('FLASK_APP_MODULE_NAME')
FLASK_APP_CLASS_NAME = os.getenv('FLASK_APP_CLASS_NAME')
FLASK_APP_KWARGS_DICT_STR = os.getenv('FLASK_APP_KWARGS_DICT')
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

# Environment Variable to enable cors
CORS_ENABLED = os.environ.get('CORS_ENABLED', False)


def create_app(*, config_module_class: str) -> Flask:
"""
Expand Down Expand Up @@ -61,6 +64,8 @@ def create_app(*, config_module_class: str) -> Flask:
else:
app = Flask(__name__)

if CORS_ENABLED:
CORS(app)
config_module_class = \
os.getenv('METADATA_SVC_CONFIG_MODULE_CLASS') or config_module_class
app.config.from_object(config_module_class)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ amundsen-common==0.2.6
flasgger==0.9.3
Flask-RESTful==0.3.6
Flask==1.0.2
flask-cors==3.0.8
gremlinpython==3.4.3
aniso8601==3.0.0
attrs==19.1.0
Expand Down

0 comments on commit c360660

Please sign in to comment.