import { NextRequest, NextResponse } from "next/server"; // Proxy (ex-middleware) always runs server-side, so it targets the API over the loopback rather than a relative URL. const BASE = process.env.PHONIX_INTERNAL_API_URL ?? process.env.NEXT_PUBLIC_API_URL ?? "http://127.0.0.1:5228"; let cache = { on: false, at: 0 }; async function maintenanceOn(): Promise { if (Date.now() - cache.at < 15000) return cache.on; try { const res = await fetch(`${BASE}/api/advanced-settings`, { cache: "no-store" }); const data = await res.json(); cache = { on: Boolean(data.maintenanceMode), at: Date.now() }; } catch { cache = { on: false, at: Date.now() }; } return cache.on; } // Per-request nonce so script-src can drop 'unsafe-inline'/'unsafe-eval': without this, CSP was allowing ANY // inline