From c2552d2e34e5388686349fa67ef26fc347b9871e Mon Sep 17 00:00:00 2001 From: Gigi Date: Fri, 7 Nov 2025 19:08:08 +0100 Subject: [PATCH] feat: add detailed logging for gateway metadata fetch Add comprehensive logging to diagnose why gateway fetch is failing: - Log the exact URL being fetched - Log HTTP status on failure - Log response length on success - Log which OG tags were found/missing - Add detailed error information This will help identify if the issue is: - Fetch timeout/failure - Missing OG tags in response - Regex pattern mismatch --- api/services/articleMeta.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/api/services/articleMeta.ts b/api/services/articleMeta.ts index f3101704..a54c9a3e 100644 --- a/api/services/articleMeta.ts +++ b/api/services/articleMeta.ts @@ -98,25 +98,37 @@ export async function fetchArticleMetadataViaGateway(naddr: string): Promise controller.abort(), 2000) - const resp = await fetch(`https://njump.to/${naddr}`, { + const url = `https://njump.to/${naddr}` + console.log(`Fetching from gateway: ${url}`) + + const resp = await fetch(url, { redirect: 'follow', signal: controller.signal }) clearTimeout(timeout) if (!resp.ok) { + console.error(`Gateway fetch failed: ${resp.status} ${resp.statusText} for ${url}`) return null } const html = await resp.text() + console.log(`Gateway response length: ${html.length} chars`) + + const pick = (re: RegExp) => { + const match = html.match(re) + return match?.[1] ? match[1].trim() : '' + } - const pick = (re: RegExp) => (html.match(re)?.[1] ?? '').trim() const title = pick(/]+property=["']og:title["'][^>]+content=["']([^"']+)["']/i) || pick(/]*>([^<]+)<\/title>/i) const summary = pick(/]+property=["']og:description["'][^>]+content=["']([^"']+)["']/i) const image = pick(/]+property=["']og:image["'][^>]+content=["']([^"']+)["']/i) + console.log(`Parsed from gateway - title: ${title ? 'found' : 'missing'}, summary: ${summary ? 'found' : 'missing'}, image: ${image ? 'found' : 'missing'}`) + if (!title && !summary && !image) { + console.log('No OG metadata found in gateway response') return null } @@ -128,6 +140,9 @@ export async function fetchArticleMetadataViaGateway(naddr: string): Promise