diff --git a/bigchaindb/web/server.py b/bigchaindb/web/server.py index bcd44d11..2740d572 100644 --- a/bigchaindb/web/server.py +++ b/bigchaindb/web/server.py @@ -2,11 +2,12 @@ The application is implemented in Flask and runs using Gunicorn. """ - +import os import copy import multiprocessing from flask import Flask +from flask_cors import CORS import gunicorn.app.base from bigchaindb import utils @@ -60,6 +61,30 @@ def create_app(*, debug=False, threads=4): app = Flask(__name__) + hostname = os.environ.get('DOCKER_MACHINE_IP', 'localhost') + + if not hostname: + hostname = 'localhost' + + origins = ('^(https?://)?(www\.)?({}|0|0.0.0.0|' + 'localhost|127.0.0.1)(\.com)?:\d{{1,5}}$').format(hostname), + CORS(app, + origins=origins, + headers=( + 'x-requested-with', + 'content-type', + 'accept', + 'origin', + 'authorization', + 'x-csrftoken', + 'withcredentials', + 'cache-control', + 'cookie', + 'session-id', + ), + supports_credentials=True, + ) + app.debug = debug app.config['bigchain_pool'] = utils.pool(Bigchain, size=threads) diff --git a/setup.py b/setup.py index 7a38bb1f..e74d4ee1 100644 --- a/setup.py +++ b/setup.py @@ -70,6 +70,7 @@ install_requires = [ 'python-rapidjson==0.0.8', 'logstats>=0.2.1', 'flask>=0.10.1', + 'flask-cors==2.1.2', 'flask-restful~=0.3.0', 'requests~=2.9', 'gunicorn~=19.0',