Skip to content

Commit

Permalink
Solves #17 when running with ENABLE_CORS=1 env variable
Browse files Browse the repository at this point in the history
* Uses [Flask-Cors](https://flask-cors.readthedocs.io/en/latest/)
* Adds default config `ENABLE_CORS = False` + env var
* Adds default config `CORS_ORIGINS = "*"` + env var

:v:
  • Loading branch information
GabLeRoux committed Jun 13, 2017
1 parent 2a17483 commit 07cedc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions requestbin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from flask import Flask, redirect, url_for
import config, os

import config
import os
from cStringIO import StringIO

from flask import Flask
from flask_cors import CORS


class WSGIRawBody(object):
def __init__(self, application):
self.application = application
Expand Down Expand Up @@ -33,6 +36,9 @@ def callback(status, headers, exc_info=None):

app = Flask(__name__)

if os.environ.get('ENABLE_CORS', config.ENABLE_CORS):
cors = CORS(app, resources={r"*": {"origins": os.environ.get('CORS_ORIGINS', config.CORS_ORIGINS)}})

from werkzeug.contrib.fixers import ProxyFix
app.wsgi_app = WSGIRawBody(ProxyFix(app.wsgi_app))

Expand Down
3 changes: 3 additions & 0 deletions requestbin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

PORT_NUMBER = 4000

ENABLE_CORS = False
CORS_ORIGINS = "*"

FLASK_SESSION_SECRET_KEY = os.environ.get("SESSION_SECRET_KEY", "N1BKhJLnBqLpexOZdklsfDKFJDKFadsfs9a3r324YB7B73AglRmrHMDQ9RhXz35")

BIN_TTL = 48*3600
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ feedparser==5.1.3
Jinja2==2.7
Werkzeug==0.9.3
Flask==0.10.1
Flask-Cors==3.0.2
redis==2.7.6
msgpack-python==0.1.12
python-dateutil==2.1
gunicorn
bugsnag
blinker
blinker

0 comments on commit 07cedc9

Please sign in to comment.