Ausgaben-WebApp: Puppet-Modul (Flask + Gunicorn + SQLite, Docker Compose)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""App-Factory für die Ausgaben-WebApp."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from .db import init_db
|
||||
from .auth import login_manager
|
||||
from .routes import bp as main_bp
|
||||
|
||||
|
||||
def create_app() -> Flask:
|
||||
"""Erzeugt und konfiguriert die Flask-Anwendung."""
|
||||
app = Flask(__name__)
|
||||
|
||||
# Sicherheits-Schlüssel: in Produktion aus der Umgebungsvariable ziehen.
|
||||
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "dev-only-change-me")
|
||||
|
||||
# Datenbank-Pfad: per Env gesetzt (im Container auf ein Volume), sonst lokal.
|
||||
db_path = Path(
|
||||
os.environ.get("DATABASE_PATH", str(Path(__file__).resolve().parent.parent / "data" / "ausgaben.db"))
|
||||
)
|
||||
db_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
app.config["DATABASE_PATH"] = str(db_path)
|
||||
|
||||
app.config["SESSION_COOKIE_HTTPONLY"] = True
|
||||
app.config["SESSION_COOKIE_SAMESITE"] = "Lax"
|
||||
|
||||
# Erweiterungen initialisieren (DB + Login).
|
||||
init_db(app)
|
||||
login_manager.init_app(app)
|
||||
|
||||
# Routen registrieren.
|
||||
app.register_blueprint(main_bp)
|
||||
|
||||
return app
|
||||
Reference in New Issue
Block a user