-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
79 lines (59 loc) · 1.95 KB
/
Copy pathapp.py
File metadata and controls
79 lines (59 loc) · 1.95 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""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")
def get_db_path_from_config():
database_uri = app.config.get("SQLALCHEMY_DATABASE_URI", "")
if database_uri.startswith("sqlite:///"):
return database_uri.replace("sqlite:///", "")
return None
db_path = get_db_path_from_config()
if db_path:
db_dir = os.path.dirname(db_path)
if db_dir and not os.path.exists(db_dir):
os.makedirs(db_dir, exist_ok=True)
init_database(db_path)
print(f"Database initialized at: {db_path}")
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__":
data_folder = app.config.get("DATA_FOLDER_PATH")
upload_folder = app.config.get("UPLOAD_FOLDER")
app.run(debug=FLASK_DEBUG, host=DEFAULT_HOST, port=PORT, ssl_context=SSL)