Created
June 28, 2018 10:25
-
-
Save bussiere/b76115645d5b6296fa42a5d3d25600ed to your computer and use it in GitHub Desktop.
Stand example of flask micro service with authorisation
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
from flask import Flask | |
from flask import jsonify | |
from flask_cors import CORS | |
import sys | |
import os | |
def error(e): | |
exc_type, exc_obj, exc_tb = sys.exc_info() | |
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] | |
return str(exc_type, fname, exc_tb.tb_lineno) | |
app = Flask(__name__) | |
cors = CORS(app, resources={r'/*': {"origins": '*'}}) | |
@app.route("/",methods=['POST','GET','OPTION']) | |
def hello(): | |
try : | |
return jsonify({"status": "ok"}) | |
except Exception as e : | |
return jsonify({"status": "ko","exception":error(e)}) | |
@app.after_request | |
def after_request(response): | |
response.headers.add('Access-Control-Allow-Origin', '*') | |
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') | |
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS') | |
return response | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0', port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment