from flask import Flask, redirect, g, send_file import secrets import os from .app import bp as app_bp app = Flask(__name__) app.config["DATABASE"] = "data/books.sqlite" app.config["SECRET_KEY"] = secrets.token_hex() app.register_blueprint(app_bp) @app.route("/") def index(): return redirect("/app", 301) @app.route("/favicon.ico") def favicon(): return send_file("static/favicon.ico") @app.route("/") def handle_redirect(path): path = path if path.startswith("/") else "/"+path if not path.startswith("/app"): return redirect("/app"+path, 301) abort(404) @app.after_request def after_request(response): """Automatically close db after each request""" if ('db' in g) and (g.db is not None): g.db.close() return response