- GET /api/health prüft die Datenbankverbindung - SQLite im WAL-Modus unter /data/app.db - Auslieferung des gebauten Frontends mit SPA-Fallback - leere Basis-Migration, Tests mit pytest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from pathlib import Path
|
|
|
|
from fastapi import FastAPI, HTTPException
|
|
from fastapi.responses import FileResponse
|
|
|
|
from app import __version__
|
|
from app.api import health
|
|
from app.config import get_settings
|
|
|
|
|
|
def _register_frontend(app: FastAPI, static_dir: Path) -> None:
|
|
"""Serve the built Vue SPA; unknown non-API paths fall back to index.html."""
|
|
root = static_dir.resolve()
|
|
index_file = root / "index.html"
|
|
|
|
@app.get("/{path:path}", include_in_schema=False)
|
|
def spa(path: str) -> FileResponse:
|
|
if path == "api" or path.startswith("api/") or not index_file.is_file():
|
|
raise HTTPException(status_code=404)
|
|
candidate = (root / path).resolve()
|
|
if path and candidate.is_relative_to(root) and candidate.is_file():
|
|
return FileResponse(candidate)
|
|
return FileResponse(index_file, headers={"Cache-Control": "no-cache"})
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
settings = get_settings()
|
|
app = FastAPI(
|
|
title="LAN-Clipboard",
|
|
version=__version__,
|
|
docs_url="/api/docs",
|
|
openapi_url="/api/openapi.json",
|
|
redoc_url=None,
|
|
)
|
|
app.include_router(health.router, prefix="/api")
|
|
_register_frontend(app, settings.static_dir)
|
|
return app
|
|
|
|
|
|
app = create_app()
|