210304394e
Implements issue #5. Off by default; set LIVEVIEW_KEY in .env to enable. No JWT required — key-based auth via ?key= query param. Returns 403 when disabled or key is wrong. Read-only ReactFlow canvas (pan/zoom, no editing). Standalone mode loads from localStorage without a key. Includes 8 backend tests and 9 frontend tests.
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from collections.abc import AsyncGenerator
|
|
from contextlib import asynccontextmanager
|
|
from typing import Any
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.routes import auth, canvas, edges, liveview, nodes, scan, status
|
|
from app.core.config import settings
|
|
from app.core.scheduler import start_scheduler, stop_scheduler
|
|
from app.db.database import init_db
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|
await init_db()
|
|
settings.load_overrides()
|
|
start_scheduler()
|
|
yield
|
|
stop_scheduler()
|
|
|
|
|
|
app = FastAPI(
|
|
title="Homelable API",
|
|
version="1.3.3",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["GET", "POST", "PUT", "PATCH", "DELETE"],
|
|
allow_headers=["Authorization", "Content-Type"],
|
|
)
|
|
|
|
app.include_router(auth.router, prefix="/api/v1/auth", tags=["auth"])
|
|
app.include_router(nodes.router, prefix="/api/v1/nodes", tags=["nodes"])
|
|
app.include_router(edges.router, prefix="/api/v1/edges", tags=["edges"])
|
|
app.include_router(canvas.router, prefix="/api/v1/canvas", tags=["canvas"])
|
|
app.include_router(scan.router, prefix="/api/v1/scan", tags=["scan"])
|
|
app.include_router(status.router, prefix="/api/v1/status", tags=["status"])
|
|
app.include_router(liveview.router, prefix="/api/v1/liveview", tags=["liveview"])
|
|
|
|
|
|
@app.get("/api/v1/health")
|
|
async def health() -> dict[str, Any]:
|
|
return {"status": "ok"}
|