"""FastAPI application that exposes the scan API and serves the front-end.""" from __future__ import annotations import os from pathlib import Path from fastapi import FastAPI from fastapi.responses import FileResponse from fastapi.staticfiles import StaticFiles from network_mapper.scanner import NetworkScanner BASE_DIR = Path(__file__).resolve().parent.parent FRONTEND_DIR = BASE_DIR / "frontend" app = FastAPI(title="LAN Graph Explorer") scanner = NetworkScanner( ssh_user=os.environ.get("SSH_USER"), ssh_key_path=os.environ.get("SSH_KEY_PATH"), ) app.mount("/static", StaticFiles(directory=FRONTEND_DIR), name="static") @app.get("/api/scan") async def api_scan(cidr: str | None = None, concurrency: int = 64, ssh_timeout: float = 5.0): """Run a fresh scan and return the topology graph.""" result = await scanner.scan(cidr=cidr, concurrency=concurrency, ssh_timeout=ssh_timeout) return result.to_dict() @app.get("/") async def serve_frontend(): return FileResponse(FRONTEND_DIR / "index.html")