summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-10-27 20:07:36 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-10-27 21:25:05 +0100
commit045a195366c03eb259669099a21adbf2c6754da1 (patch)
tree422f8c235d5430165d4e7eb1e7c1d9092b7b3519 /api
parent38fc6fa35ca4545a6068aaa759359c271c9f5197 (diff)
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.
Diffstat (limited to 'api')
-rwxr-xr-xapi/main.py12
-rw-r--r--api/pytest.ini1
2 files changed, 4 insertions, 9 deletions
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'])
diff --git a/api/pytest.ini b/api/pytest.ini
index 775a8ff4..8c28be16 100644
--- a/api/pytest.ini
+++ b/api/pytest.ini
@@ -2,4 +2,3 @@
env =
OPENDC_FLASK_TESTING=True
OPENDC_FLASK_SECRET=Secret
- OPENDC_SERVER_BASE_URL=localhost