diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-05-30 17:27:04 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-05-30 17:27:04 +0200 |
| commit | 0890fdd951d021308550a0db2e7b6f2593512957 (patch) | |
| tree | a0050b153242ccde662fc0a957a79fc7a7edc4b4 /cli/app/server/web.py | |
initial site copied in
Diffstat (limited to 'cli/app/server/web.py')
| -rw-r--r-- | cli/app/server/web.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/cli/app/server/web.py b/cli/app/server/web.py new file mode 100644 index 0000000..49618d2 --- /dev/null +++ b/cli/app/server/web.py @@ -0,0 +1,59 @@ +import os +import logging +import logging.handlers + +logger = logging.getLogger("") +logger.setLevel(logging.DEBUG) +handler = logging.handlers.RotatingFileHandler("flask.log", + maxBytes=3000000, backupCount=2) +formatter = logging.Formatter( + '[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s') +handler.setFormatter(formatter) +logger.addHandler(handler) +logging.getLogger().addHandler(logging.StreamHandler()) + +from flask import Flask, Blueprint, send_from_directory, request +from app.sql.common import db, connection_url + +from app.settings import app_cfg +from app.controllers.collection_controller import CollectionView +from app.controllers.upload_controller import UploadView + +def create_app(script_info=None): + """ + functional pattern for creating the flask app + """ + logging.debug("Starting Flask app...") + + app = Flask(__name__, static_folder=app_cfg.DIR_STATIC, static_url_path='/static') + app.config['SQLALCHEMY_DATABASE_URI'] = connection_url + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + + db.init_app(app) + + CollectionView.register(app, route_prefix='/api/v1/') + UploadView.register(app, route_prefix='/api/v1/') + + index_html = 'index.html' + + @app.errorhandler(404) + def page_not_found(e): + return app.send_static_file(index_html), 200 + # path = os.path.join(os.path.dirname(__file__), './static/index.html') + # with open(path, "r") as f: + # return f.read(), 200 + + @app.route('/', methods=['GET']) + def index(): + return app.send_static_file('index.html') + + @app.route('/favicon.ico') + def favicon(): + return send_from_directory(os.path.join(app.root_path, 'static/img/'), + 'favicon.ico',mimetype='image/vnd.microsoft.icon') + + @app.shell_context_processor + def shell_context(): + return { 'app': app, 'db': db } + + return app |
