Skip to content

Commit 9b7b95b

Browse files
Merge branch 'feat/extensions' of https://github.com/Geode-solutions/OpenGeodeWeb-Back into feat/extensions
2 parents 24d80c8 + 1043160 commit 9b7b95b

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

src/opengeodeweb_back/app.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@
1414
from opengeodeweb_back.routes.create import blueprint_create
1515
from opengeodeweb_microservice.database import connection
1616

17+
1718
def create_app(name: str) -> flask.Flask:
1819
app = flask.Flask(name)
1920

2021
""" Config variables """
21-
FLASK_DEBUG = True if os.environ.get("FLASK_DEBUG", default=None) == "True" else False
22+
FLASK_DEBUG = (
23+
True if os.environ.get("FLASK_DEBUG", default=None) == "True" else False
24+
)
2225
if FLASK_DEBUG == False:
2326
app.config.from_object(app_config.ProdConfig)
2427
else:
2528
app.config.from_object(app_config.DevConfig)
26-
29+
2730
if FLASK_DEBUG == False:
2831
SECONDS_BETWEEN_SHUTDOWNS: float = float(
2932
app.config.get("SECONDS_BETWEEN_SHUTDOWNS") or 60.0
@@ -36,7 +39,9 @@ def create_app(name: str) -> flask.Flask:
3639
def before_request() -> flask.Response | None:
3740
if flask.request.method == "OPTIONS":
3841
response = flask.make_response()
39-
response.headers["Access-Control-Allow-Methods"] = "GET,POST,PUT,DELETE,OPTIONS"
42+
response.headers["Access-Control-Allow-Methods"] = (
43+
"GET,POST,PUT,DELETE,OPTIONS"
44+
)
4045
return response
4146
utils_functions.before_request(flask.current_app)
4247
return None
@@ -49,13 +54,11 @@ def teardown_request(exception: BaseException | None) -> None:
4954
def errorhandler(exception: HTTPException) -> tuple[dict[str, Any], int] | Response:
5055
return utils_functions.handle_exception(exception)
5156

52-
5357
@app.errorhandler(Exception)
5458
def handle_generic_exception(exception: Exception) -> Response:
5559
print("\033[91mError:\033[0m \033[91m" + str(exception) + "\033[0m", flush=True)
5660
return flask.make_response({"description": str(exception)}, 500)
5761

58-
5962
@app.route(
6063
"/error",
6164
methods=["POST"],
@@ -64,13 +67,11 @@ def return_error() -> Response:
6467
flask.abort(500, f"Test")
6568
return flask.make_response({}, 500)
6669

67-
6870
@app.route("/", methods=["POST"])
6971
@cross_origin()
7072
def root() -> Response:
7173
return flask.make_response({}, 200)
7274

73-
7475
@app.route("/kill", methods=["POST"])
7576
@cross_origin()
7677
def kill() -> None:
@@ -79,6 +80,7 @@ def kill() -> None:
7980

8081
return app
8182

83+
8284
def register_ogw_back_blueprints(app: flask.Flask) -> None:
8385
app.register_blueprint(
8486
blueprint_routes.routes,
@@ -96,13 +98,23 @@ def register_ogw_back_blueprints(app: flask.Flask) -> None:
9698
name="opengeodeweb_create",
9799
)
98100

101+
99102
def run_server(app: Flask) -> None:
100103
parser = argparse.ArgumentParser(
101104
prog="OpenGeodeWeb-Back", description="Backend server for OpenGeodeWeb"
102105
)
103-
parser.add_argument("--host", type=str, default=app.config.get("DEFAULT_HOST"), help="Host to run on")
104106
parser.add_argument(
105-
"-p", "--port", type=int, default=app.config.get("DEFAULT_PORT"), help="Port to listen on"
107+
"--host",
108+
type=str,
109+
default=app.config.get("DEFAULT_HOST"),
110+
help="Host to run on",
111+
)
112+
parser.add_argument(
113+
"-p",
114+
"--port",
115+
type=int,
116+
default=app.config.get("DEFAULT_PORT"),
117+
help="Port to listen on",
106118
)
107119
parser.add_argument(
108120
"-d",
@@ -160,5 +172,10 @@ def run_server(app: Flask) -> None:
160172

161173
connection.init_database(db_path)
162174
print(f"Database initialized at: {db_path}", flush=True)
163-
app.run(debug=args.debug, host=args.host, port=args.port, ssl_context=app.config.get("SSL"))
175+
app.run(
176+
debug=args.debug,
177+
host=args.host,
178+
port=args.port,
179+
ssl_context=app.config.get("SSL"),
180+
)
164181
print("Server stopped", flush=True)

0 commit comments

Comments
 (0)