2024-04-05 17:24:02 +02:00
|
|
|
from flask import Flask, redirect, g
|
2024-04-03 18:30:04 +02:00
|
|
|
import secrets
|
2024-04-03 16:54:54 +02:00
|
|
|
|
2024-04-05 17:24:02 +02:00
|
|
|
from .app import bp as app_bp
|
2024-04-03 16:54:54 +02:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
app.config["DATABASE"] = "data/books.sqlite"
|
2024-04-03 18:30:04 +02:00
|
|
|
app.config["SECRET_KEY"] = secrets.token_hex()
|
2024-04-03 16:54:54 +02:00
|
|
|
|
2024-04-05 17:24:02 +02:00
|
|
|
app.register_blueprint(app_bp)
|
2024-04-03 16:54:54 +02:00
|
|
|
|
2024-04-05 17:24:02 +02:00
|
|
|
@app.route("/<path>")
|
|
|
|
def handle_redirect(path):
|
|
|
|
if not path.startswith("/app"):
|
|
|
|
return redirect("/app"+path, 301)
|
|
|
|
abort(404)
|
2024-04-03 18:30:04 +02:00
|
|
|
|
2024-04-03 16:54:54 +02:00
|
|
|
@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
|