From 045a195366c03eb259669099a21adbf2c6754da1 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 27 Oct 2020 20:07:36 +0100 Subject: Enable CORS for non-local deployments This change enables CORS for non-local deployment in order to allow other domains to make requests from the browser to the OpenDC API. --- api/main.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'api/main.py') diff --git a/api/main.py b/api/main.py index 46782638..93b772a1 100755 --- a/api/main.py +++ b/api/main.py @@ -27,24 +27,20 @@ if not TEST_MODE: user=os.environ['OPENDC_DB_USERNAME'], password=os.environ['OPENDC_DB_PASSWORD'], database=os.environ['OPENDC_DB'], - host=os.environ['OPENDC_DB_HOST'] if 'OPENDC_DB_HOST' in os.environ else 'localhost') + host=os.environ.get('OPENDC_DB_HOST', 'localhost')) # Set up the core app FLASK_CORE_APP = Flask(__name__) FLASK_CORE_APP.config['SECRET_KEY'] = os.environ['OPENDC_FLASK_SECRET'] FLASK_CORE_APP.json_encoder = JSONEncoder -# Set up CORS support for local setups -if 'localhost' in os.environ['OPENDC_SERVER_BASE_URL']: - CORS(FLASK_CORE_APP) +# Set up CORS support +CORS(FLASK_CORE_APP) compress = Compress() compress.init_app(FLASK_CORE_APP) -if 'OPENDC_SERVER_BASE_URL' in os.environ or 'localhost' in os.environ['OPENDC_SERVER_BASE_URL']: - SOCKET_IO_CORE = flask_socketio.SocketIO(FLASK_CORE_APP, cors_allowed_origins="*") -else: - SOCKET_IO_CORE = flask_socketio.SocketIO(FLASK_CORE_APP) +SOCKET_IO_CORE = flask_socketio.SocketIO(FLASK_CORE_APP, cors_allowed_origins="*") @FLASK_CORE_APP.route('/tokensignin', methods=['POST']) -- cgit v1.2.3 From 9fdd26b50e17c757dfa4a0874d87d929ac9ac242 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 27 Oct 2020 23:12:48 +0100 Subject: Remove api prefix from path This change removes the `api` prefix required by the API server in the path, given that we have started to host the API on its own domain (api.opendc.org) and thus does not need a prefix. --- api/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/main.py') diff --git a/api/main.py b/api/main.py index 93b772a1..387b516a 100755 --- a/api/main.py +++ b/api/main.py @@ -79,7 +79,7 @@ def sign_in(): return jsonify(**data) -@FLASK_CORE_APP.route('/api//', methods=['GET', 'POST', 'PUT', 'DELETE']) +@FLASK_CORE_APP.route('//', methods=['GET', 'POST', 'PUT', 'DELETE']) def api_call(version, endpoint_path): """Call an API endpoint directly over HTTP.""" -- cgit v1.2.3