- FastAPI-App mit SQLite-Schema (admins, sessions, connections) - Login mit Argon2, serverseitige Sessions (Token nur gehasht gespeichert) - Cookie HttpOnly/Secure/SameSite=Strict, CSRF-Token für schreibende Requests - scripts/create_admin.py zum Anlegen und Zurücksetzen von Admins - Einfaches Frontend mit Login - pytest-Tests, gepinnte requirements.txt, .env.example, .gitignore - SETUP.md Teil 4 ergänzt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""FastAPI-Einstieg."""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from .config import PROJEKT_ROOT
|
|
from .db import init_db
|
|
from .routes import auth_routes
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_app: FastAPI):
|
|
init_db()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="it-connect", lifespan=lifespan, docs_url=None, redoc_url=None)
|
|
|
|
|
|
@app.middleware("http")
|
|
async def sicherheits_header(request, call_next):
|
|
response = await call_next(request)
|
|
response.headers.setdefault("X-Content-Type-Options", "nosniff")
|
|
response.headers.setdefault("X-Frame-Options", "DENY")
|
|
response.headers.setdefault("Referrer-Policy", "no-referrer")
|
|
response.headers.setdefault(
|
|
"Content-Security-Policy",
|
|
"default-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'",
|
|
)
|
|
return response
|
|
|
|
|
|
app.include_router(auth_routes.router)
|
|
|
|
# Frontend zuletzt einhängen, damit /api/* Vorrang hat
|
|
app.mount("/", StaticFiles(directory=PROJEKT_ROOT / "frontend", html=True), name="frontend")
|