add create_app

This commit is contained in:
Dmitry Belyaev 2021-10-07 14:31:12 +03:00
parent 05ef983dc2
commit 710277abae
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
3 changed files with 30 additions and 24 deletions

27
app/app.py Normal file
View File

@ -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

View File

@ -9,4 +9,4 @@ def load_config(filename: str):
def config_location() -> str: def config_location() -> str:
return os.getenv('WEBPUB1C_CONFIG', 'config.yml') return os.getenv('WEBPUB1C_CONFIG', 'config.yml')

View File

@ -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.app import create_app
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")
app = create_app()
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) app.run(debug=True)