50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import os
|
|
|
|
from flask import Flask
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
db = SQLAlchemy()
|
|
|
|
# Die Templates/Static-Verzeichnisse liegen auf Repo-Ebene (neben dem app/ Paket),
|
|
# nicht innerhalb des Pakets. Daher relativ zur Repo-Wurzel (Ueberverzeichnis) aufloesen.
|
|
_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
def create_app():
|
|
app = Flask(
|
|
__name__,
|
|
template_folder=os.path.join(_REPO_ROOT, "templates"),
|
|
static_folder=os.path.join(_REPO_ROOT, "static"),
|
|
)
|
|
|
|
# Konfiguration aus Umgebungsvariablen (Coolify)
|
|
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "dev-secret-key")
|
|
app.config["MAX_ATTEMPTS"] = int(os.environ.get("MAX_ATTEMPTS", "10"))
|
|
app.config["DAILY_RESET_UTC"] = int(os.environ.get("DAILY_RESET_UTC", "9"))
|
|
|
|
db_host = os.environ.get("DB_HOST", "localhost")
|
|
db_port = os.environ.get("DB_PORT", "5432")
|
|
db_user = os.environ.get("DB_USER", "filmdle")
|
|
db_password = os.environ.get("DB_PASSWORD", "")
|
|
db_name = os.environ.get("DB_DATABASE", "filmdle")
|
|
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = (
|
|
f"postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
|
|
)
|
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
|
|
|
db.init_app(app)
|
|
|
|
from . import routes # noqa: F401
|
|
|
|
app.register_blueprint(routes.bp)
|
|
|
|
with app.app_context():
|
|
db.create_all()
|
|
# Seed (idempotent) beim Start, damit die App sofort funktioniert
|
|
from .seed import seed_all
|
|
|
|
seed_all()
|
|
|
|
return app
|