Files
FabledSteward/fablednetmon/app.py
T

49 lines
1.3 KiB
Python

from __future__ import annotations
from pathlib import Path
from quart import Quart
from .config import load_config
from .database import init_db
def create_app(
config_path: Path | str | None = None,
testing: bool = False,
) -> Quart:
app = Quart(__name__, template_folder="templates")
# Load config
cfg = load_config(config_path)
app.config.update(
SECRET_KEY=cfg["secret_key"],
DATABASE_URL=cfg["database"]["url"],
SESSION_LIFETIME_HOURS=cfg.get("session", {}).get("lifetime_hours", 8),
DATA_RETENTION_DAYS=cfg.get("data", {}).get("retention_days", 90),
PLUGIN_DIR=cfg.get("plugin_dir", "plugins"),
PLUGINS=cfg.get("plugins", {}),
SMTP=cfg.get("smtp", {}),
WEBHOOK=cfg.get("webhook", {}),
TESTING=testing,
_RAW_CFG=cfg,
)
# Database
if not testing:
init_db(app)
else:
from unittest.mock import MagicMock
app.db_sessionmaker = MagicMock()
# Register blueprints
from .auth.routes import auth_bp
app.register_blueprint(auth_bp)
from .dashboard.routes import dashboard_bp
app.register_blueprint(dashboard_bp)
# Health check
@app.get("/health")
async def health():
return {"status": "ok"}
return app