From 32b843908e4766705a0d13fdfa1d4538eacdc514 Mon Sep 17 00:00:00 2001 From: Gigi Date: Thu, 16 Oct 2025 15:34:50 +0200 Subject: [PATCH] debug: add logging and debug endpoint to article-og Add console logging for debugging and ?debug=1 query param to see request details in browser. --- api/article-og.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/api/article-og.ts b/api/article-og.ts index a49bda43..97ae71a6 100644 --- a/api/article-og.ts +++ b/api/article-og.ts @@ -213,10 +213,27 @@ export default async function handler(req: VercelRequest, res: VercelResponse) { } const userAgent = req.headers['user-agent'] as string | undefined + const isCrawlerRequest = isCrawler(userAgent) + + const debugInfo = { + naddr: naddr.slice(0, 20) + '...', + userAgent: userAgent?.slice(0, 80), + isCrawler: isCrawlerRequest, + url: req.url, + referer: req.headers.referer, + accept: req.headers.accept + } + + console.log('[article-og]', debugInfo) + + // Debug mode: if ?debug=1, return JSON + if (req.query.debug === '1') { + return res.status(200).json(debugInfo) + } // If it's a regular browser (not a bot), serve index.html with base tag // The rewrite preserves the URL, so SPA routing will handle /a/{naddr} - if (!isCrawler(userAgent)) { + if (!isCrawlerRequest) { const fs = await import('fs') const path = await import('path') // eslint-disable-next-line no-undef