Files
lan-clipboard/backend/app/main.py
T
dbildhauerandClaude Opus 5.5 18f0d04ce9 feat: login mit serverseitigen sessions
- POST /api/auth/login|logout, GET /api/auth/me
- Session-Token nur gehasht gespeichert, Cookie HttpOnly/Secure/SameSite=Lax
- Ablauf nach 30 Tagen Inaktivität bzw. spätestens 90 Tagen
- Sessions pro Gerät auflisten und widerrufen, Rotation beim Login
- Passwortänderung beendet alle anderen Sessions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 11:04:33 +01:00

48 lines
1.6 KiB
Python

from pathlib import Path
from fastapi import FastAPI, HTTPException, Request, status
from fastapi.responses import FileResponse, JSONResponse
from app import __version__
from app.api import auth, health
from app.config import get_settings
from app.services.users import UserError
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")
app.include_router(auth.router, prefix="/api")
@app.exception_handler(UserError)
def user_error_handler(_request: Request, exc: UserError) -> JSONResponse:
return JSONResponse({"detail": str(exc)}, status_code=status.HTTP_400_BAD_REQUEST)
_register_frontend(app, settings.static_dir)
return app
app = create_app()