diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-11-16 17:03:07 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-11-16 17:03:07 +0100 |
| commit | 92881093ae19e4d76193447c187028aee5cbe4c7 (patch) | |
| tree | 8e3b4baa4ea790b5e9b30e2fed6ed4f1b871cc5c /animism-align/cli/app/server/viewer.py | |
| parent | 77489cf313dd47122b9be80f6d49caf513a9e03c (diff) | |
getting the viewer-only version of the site working. flask command to run test server
Diffstat (limited to 'animism-align/cli/app/server/viewer.py')
| -rw-r--r-- | animism-align/cli/app/server/viewer.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/animism-align/cli/app/server/viewer.py b/animism-align/cli/app/server/viewer.py new file mode 100644 index 0000000..3eecc4e --- /dev/null +++ b/animism-align/cli/app/server/viewer.py @@ -0,0 +1,69 @@ +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.settings import app_cfg + +def create_app(script_info=None): + """ + functional pattern for creating the flask app + """ + logging.debug("Starting site viewer...") + # print(app_cfg.SERVER_NAME) + app = Flask(__name__, static_folder=app_cfg.DIR_STATIC_SITE_VIEWER, static_url_path='/') + app.config['SERVER_NAME'] = app_cfg.SERVER_NAME + app.url_map.strict_slashes = False + + # index_html = 'site.html' + + # @app.route('/episode1', methods=['GET']) + # def serve_dir_directory_index(): + # return send_from_directory(app_cfg.DIR_STATIC_SITE_VIEWER, 'episode1/index.html') + + # @app.errorhandler(404) + # def page_not_found(e): + # filename = request.url.replace(app_cfg.SERVER_NAME, '') + # print(filename) + # # return app.send_static_file(index_html), 200 + + # @app.route('/<path:filename>', methods=['GET']) + # def serve_file_in_dir(filename): + # print(filename) + # if os.path.isfile(os.path.join(app_cfg.DIR_STATIC_SITE_VIEWER, filename)): + # return send_from_directory(app_cfg.DIR_STATIC_SITE_VIEWER, filename) + # if os.path.isfile(os.path.join(app_cfg.DIR_STATIC_SITE_VIEWER, filename, 'index.html')): + # filename = os.path.join(filename, 'index.html') + # return send_from_directory(app_cfg.DIR_STATIC_SITE_VIEWER, filename) + # return 404 + + # return app.send_static_file(index_html), 200 + # path = os.path.join(os.path.dirname(__file__), 'site.html') + # with open(path, "r") as f: + # return f.read(), 200 + + # @app.route('/', methods=['GET']) + # def index(): + # return app.send_static_file('site.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 |
