From 710277abae7c6332e3ae82304e8e3538fae81a3a Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 7 Oct 2021 14:31:12 +0300 Subject: [PATCH] add create_app --- app/app.py | 27 +++++++++++++++++++++++++++ app/config.py | 2 +- pub1c-rest.py | 25 ++----------------------- 3 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 app/app.py diff --git a/app/app.py b/app/app.py new file mode 100644 index 0000000..8f57d45 --- /dev/null +++ b/app/app.py @@ -0,0 +1,27 @@ + +from flask import Flask, render_template +from flask_restful import Api +from flask_cors import CORS + +from app.api.index import add_api_resources +from app.glob import get_config, get_manager + +frontend_dir = '../frontend/dist' + + +def create_app(): + app = Flask(__name__, static_url_path='/', static_folder=frontend_dir, template_folder=frontend_dir) + api = Api(app, '/api/v1/') + add_api_resources(api) + cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) + + @app.route('/') + def index(): + return index_content + + with app.app_context(): + get_config() + get_manager() + index_content = render_template("index.html") + + return app diff --git a/app/config.py b/app/config.py index 0d7e7b3..3f54397 100644 --- a/app/config.py +++ b/app/config.py @@ -9,4 +9,4 @@ def load_config(filename: str): def config_location() -> str: - return os.getenv('WEBPUB1C_CONFIG', 'config.yml') \ No newline at end of file + return os.getenv('WEBPUB1C_CONFIG', 'config.yml') diff --git a/pub1c-rest.py b/pub1c-rest.py index 5218d26..6b955c8 100644 --- a/pub1c-rest.py +++ b/pub1c-rest.py @@ -1,28 +1,7 @@ -from flask import Flask, render_template -from flask_restful import Api -from flask_cors import CORS -from app.api.index import add_api_resources -from app.glob import get_config, get_manager - -frontend_dir = 'frontend/dist' -app = Flask(__name__, static_url_path='/', static_folder=frontend_dir, template_folder=frontend_dir) -api = Api(app, '/api/v1/') -cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) - -add_api_resources(api) - - -@app.route('/') -def index(): - return index_content - - -with app.app_context(): - get_config() - get_manager() - index_content = render_template("index.html") +from app.app import create_app +app = create_app() if __name__ == '__main__': app.run(debug=True)