fix: dashboard token via URL param + correct screenshot

- Support ?token=xxx query parameter for dashboard auth (enables
  headless browser screenshots and direct links)
- Token is saved to localStorage and URL is cleaned up
- Fix pathname matching to handle query parameters in URL
- Replace html2canvas screenshot with Playwright (accurate colors)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 09:56:21 +10:00
co-authored by Claude Opus 4.6
parent 087e26346f
commit a0f9268af5
3 changed files with 6 additions and 3 deletions
+3 -1
View File
@@ -85,7 +85,9 @@
<script> <script>
const BASE = window.location.origin; const BASE = window.location.origin;
const headers = {}; const headers = {};
const storedToken = localStorage.getItem("ocp_token"); const urlToken = new URLSearchParams(window.location.search).get("token");
const storedToken = urlToken || localStorage.getItem("ocp_token");
if (urlToken) { localStorage.setItem("ocp_token", urlToken); history.replaceState(null, "", "/dashboard"); }
if (storedToken) headers["Authorization"] = `Bearer ${storedToken}`; if (storedToken) headers["Authorization"] = `Bearer ${storedToken}`;
async function api(path) { async function api(path) {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 857 KiB

After

Width:  |  Height:  |  Size: 214 KiB

+3 -2
View File
@@ -1039,7 +1039,8 @@ const server = createServer(async (req, res) => {
if (req.method === "OPTIONS") { res.writeHead(204); res.end(); return; } if (req.method === "OPTIONS") { res.writeHead(204); res.end(); return; }
// 3-mode auth: none | shared | multi // 3-mode auth: none | shared | multi
const isPublicEndpoint = req.url === "/health" || req.url === "/dashboard"; const pathname = req.url.split("?")[0];
const isPublicEndpoint = pathname === "/health" || pathname === "/dashboard";
let authKeyName = "local"; let authKeyName = "local";
let authKeyId = null; let authKeyId = null;
@@ -1217,7 +1218,7 @@ const server = createServer(async (req, res) => {
} }
// GET /dashboard — web dashboard // GET /dashboard — web dashboard
if (req.url === "/dashboard" && req.method === "GET") { if (pathname === "/dashboard" && req.method === "GET") {
try { try {
const html = readFileSync(join(__dirname, "dashboard.html"), "utf8"); const html = readFileSync(join(__dirname, "dashboard.html"), "utf8");
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }); res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });