From 6c22ddac8e63ffbdffb76b8f2ed16d39d76bf1c9 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 25 May 2024 17:00:44 +0200 Subject: [PATCH] feat: Refactor app initialization for clarity Refactored app initialization in `main.py` by encapsulating the Flask server start-up configuration into a `main` function. This change improves code readability and organization, making the execution flow clearer, especially when the application starts or is debugged. Previously, the server start-up logic was directly in the global scope guarded by `if __name__ == "__main__":`, making the logic slightly less organized. Moving this into a dedicated function allows for potential expansion and easier testing. Additionally, ensured data initialization occurs after server start-up to align with best practices for initial data loading. --- src/structables/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/structables/main.py b/src/structables/main.py index 65cb714..7126b6e 100644 --- a/src/structables/main.py +++ b/src/structables/main.py @@ -13,8 +13,11 @@ app.typesense_api_key = get_typesense_api_key() init_routes(app) -if __name__ == "__main__": +def main(): app.run(port=app.config['PORT'], host=app.config['LISTEN_HOST'], debug=app.config['DEBUG']) +if __name__ == "__main__": + main() + # Initialize data when the server starts update_data(app) \ No newline at end of file