|
| 1 | +""" Packages """ |
| 2 | +import os |
| 3 | + |
| 4 | +import flask |
| 5 | +import flask_cors |
| 6 | +from werkzeug.exceptions import HTTPException |
| 7 | + |
| 8 | +from werkzeug.exceptions import HTTPException |
| 9 | + |
| 10 | +from src.opengeodeweb_back.routes import blueprint_routes |
| 11 | + |
| 12 | + |
| 13 | +""" Global config """ |
| 14 | +app = flask.Flask(__name__) |
| 15 | + |
| 16 | +""" Config variables """ |
| 17 | +FLASK_DEBUG = True if os.environ.get("FLASK_DEBUG", default=None) == "True" else False |
| 18 | + |
| 19 | +if FLASK_DEBUG == False: |
| 20 | + app.config.from_object("config.ProdConfig") |
| 21 | +else: |
| 22 | + app.config.from_object("config.DevConfig") |
| 23 | + |
| 24 | + |
| 25 | +PORT = int(app.config.get("PORT")) |
| 26 | +ORIGINS = app.config.get("ORIGINS") |
| 27 | +SSL = app.config.get("SSL") |
| 28 | + |
| 29 | +flask_cors.CORS(app, origins=ORIGINS) |
| 30 | +app.register_blueprint( |
| 31 | + blueprint_routes.routes, |
| 32 | + url_prefix="/", |
| 33 | + name="blueprint_routes", |
| 34 | +) |
| 35 | + |
| 36 | + |
| 37 | +@app.errorhandler(HTTPException) |
| 38 | +def handle_exception(e): |
| 39 | + response = e.get_response() |
| 40 | + response.data = flask.json.dumps( |
| 41 | + { |
| 42 | + "code": e.code, |
| 43 | + "name": e.name, |
| 44 | + "description": e.description, |
| 45 | + } |
| 46 | + ) |
| 47 | + response.content_type = "application/json" |
| 48 | + return response |
| 49 | + |
| 50 | + |
| 51 | +# ''' Main ''' |
| 52 | +if __name__ == "__main__": |
| 53 | + print(f"Python is running in {FLASK_DEBUG} mode") |
| 54 | + app.run(debug=FLASK_DEBUG, host="0.0.0.0", port=PORT, ssl_context=SSL) |
0 commit comments