-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
63 lines (47 loc) · 1.47 KB
/
Copy pathapp.py
File metadata and controls
63 lines (47 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Packages"""
import os
import flask
import flask_cors
from werkzeug.exceptions import HTTPException
from src.opengeodeweb_back.routes import blueprint_routes
from src.opengeodeweb_back.routes.models import blueprint_models
from src.opengeodeweb_back.utils_functions import handle_exception
from src.opengeodeweb_back import app_config
from opengeodeweb_microservice.database.connection import init_database
""" Global config """
app = flask.Flask(__name__)
""" Config variables """
FLASK_DEBUG = True if os.environ.get("FLASK_DEBUG", default=None) == "True" else False
if FLASK_DEBUG == False:
app.config.from_object(app_config.ProdConfig)
else:
app.config.from_object(app_config.DevConfig)
DEFAULT_HOST = app.config.get("DEFAULT_HOST")
PORT = int(app.config.get("DEFAULT_PORT"))
ORIGINS = app.config.get("ORIGINS")
SSL = app.config.get("SSL")
flask_cors.CORS(app, origins=ORIGINS)
app.register_blueprint(
blueprint_routes.routes,
url_prefix="/",
name="blueprint_routes",
)
app.register_blueprint(
blueprint_models.routes,
url_prefix="/models",
name="blueprint_models",
)
@app.errorhandler(HTTPException)
def errorhandler(e):
return handle_exception(e)
@app.route(
"/error",
methods=["POST"],
)
def return_error():
flask.abort(500, f"Test")
# ''' Main '''
if __name__ == "__main__":
init_database(app)
print(f"Python is running in {FLASK_DEBUG} mode")
app.run(debug=FLASK_DEBUG, host=DEFAULT_HOST, port=PORT, ssl_context=SSL)