Created
December 25, 2015 15:19
-
-
Save dcrystalj/7ee64d3dc7d1ffadd3c8 to your computer and use it in GitHub Desktop.
flask init app with CORS support
This file contains hidden or 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
| from flask import Flask, Response | |
| from flask.ext.cors import CORS | |
| import os.path | |
| import logging | |
| def root_dir(): # pragma: no cover | |
| return os.path.abspath(os.path.dirname(__file__)) | |
| def get_file(filename): # pragma: no cover | |
| try: | |
| src = os.path.join(root_dir(), filename) | |
| # Figure out how flask returns static files | |
| # Tried: | |
| # - render_template | |
| # - send_file | |
| # This should not be so non-obvious | |
| return open(src).read() | |
| except IOError as exc: | |
| return str(exc) | |
| app = Flask(__name__) | |
| CORS(app) | |
| logging.getLogger('flask_cors').level = logging.DEBUG | |
| @app.route("/") | |
| def helloWorld(): | |
| content = get_file('mbills.html') | |
| return Response(content, mimetype="text/html") | |
| @app.route("/lol", methods=['GET', 'POST']) | |
| def lol(): | |
| return "asdfs" | |
| if __name__ == '__main__': | |
| app.run(debug=True,port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment