Last active
October 8, 2016 07:28
-
-
Save hxer/98d5b79971921bfd366404b05328c109 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
""" | |
import functools | |
from flask import Flask, jsonify | |
from gevent.pywsgi import WSGIServer | |
def create_app(): | |
app = Flask(__name__) | |
def crossdomain(f): | |
@functools.wraps(f) | |
def wrapper(*args, **kwargs): | |
resp = f(*args, **kwargs) | |
h = resp.headers | |
h['Access-Control-Allow-Origin'] = '*' | |
h['Access-Control-Allow-Methods'] = 'GET' | |
return resp | |
return wrapper | |
@app.route('/') | |
@crossdomain | |
def bar(): | |
data = {"demo": "flask json"} | |
return jsonify(data) | |
return app | |
if __name__ == '__main__': | |
app = create_app() | |
http_server = WSGIServer(('', 5000), app) | |
http_server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment