added CORS for localhost

This commit is contained in:
diminator 2017-03-20 21:35:47 +01:00
parent 43f779a18b
commit a3b01147e5
No known key found for this signature in database
GPG Key ID: C3D8590E6D0D439A
2 changed files with 27 additions and 1 deletions

View File

@ -2,11 +2,12 @@
The application is implemented in Flask and runs using Gunicorn. The application is implemented in Flask and runs using Gunicorn.
""" """
import os
import copy import copy
import multiprocessing import multiprocessing
from flask import Flask from flask import Flask
from flask_cors import CORS
import gunicorn.app.base import gunicorn.app.base
from bigchaindb import utils from bigchaindb import utils
@ -60,6 +61,30 @@ def create_app(*, debug=False, threads=4):
app = Flask(__name__) 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.debug = debug
app.config['bigchain_pool'] = utils.pool(Bigchain, size=threads) app.config['bigchain_pool'] = utils.pool(Bigchain, size=threads)

View File

@ -70,6 +70,7 @@ install_requires = [
'python-rapidjson==0.0.8', 'python-rapidjson==0.0.8',
'logstats>=0.2.1', 'logstats>=0.2.1',
'flask>=0.10.1', 'flask>=0.10.1',
'flask-cors==2.1.2',
'flask-restful~=0.3.0', 'flask-restful~=0.3.0',
'requests~=2.9', 'requests~=2.9',
'gunicorn~=19.0', 'gunicorn~=19.0',