Skip to content
Permalink
Browse files

Solves Runscope#17 when running with ENABLE_CORS=1 env variable

* 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

✌️
  • Loading branch information...
GabLeRoux committed Jun 13, 2017
1 parent 2a17483 commit 07cedc9545f00fe41486c0020c081f121bb33b5c
Showing with 14 additions and 4 deletions.
  1. +9 −3 requestbin/__init__.py
  2. +3 −0 requestbin/config.py
  3. +2 −1 requirements.txt
@@ -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
@@ -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))

@@ -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
@@ -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.
You can’t perform that action at this time.