From 1f4f55d4fc870eb373c3bbd935ed4df0755b52fb Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 18 Mar 2026 17:23:12 +0100 Subject: [PATCH] fix(patches): add internal URL rewrite to webmention livefetch The livefetch patch was fetching postUrl (the public HTTPS URL) which fails behind the nginx jail. Now rewrites to INTERNAL_FETCH_URL so the live page fetch goes through nginx on the internal network. Without this, likes/reposts/bookmarks fall back to stored content which has no microformat links, resulting in 0 webmentions sent. Co-Authored-By: Claude Opus 4.6 --- scripts/patch-webmention-sender-livefetch.mjs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/patch-webmention-sender-livefetch.mjs b/scripts/patch-webmention-sender-livefetch.mjs index 61692bbd..541fad0c 100644 --- a/scripts/patch-webmention-sender-livefetch.mjs +++ b/scripts/patch-webmention-sender-livefetch.mjs @@ -76,16 +76,27 @@ const retryPatchedBlock = ` // If no content, try fetching the published const newBlock = ` // [patched:livefetch] Always fetch the live page so template-rendered links // (u-in-reply-to, u-like-of, u-bookmark-of, u-repost-of, etc.) are included. // Stored content only has the post body, not these microformat links. + // Rewrite public URL to internal URL for jailed setups where the server + // can't reach its own public HTTPS URL. let contentToProcess = ""; try { + const _wmInternalBase = (() => { + if (process.env.INTERNAL_FETCH_URL) return process.env.INTERNAL_FETCH_URL.replace(/\\\\/+$/, ""); + const port = process.env.PORT || "3000"; + return \\\`http://localhost:\\\${port}\\\`; + })(); + const _wmPublicBase = (process.env.PUBLICATION_URL || process.env.SITE_URL || "").replace(/\\\\/+$/, ""); + const fetchUrl = (_wmPublicBase && postUrl.startsWith(_wmPublicBase)) + ? _wmInternalBase + postUrl.slice(_wmPublicBase.length) + : postUrl; const _ac = new AbortController(); const _timeout = setTimeout(() => _ac.abort(), 15000); - const pageResponse = await fetch(postUrl, { signal: _ac.signal }); + const pageResponse = await fetch(fetchUrl, { signal: _ac.signal }); clearTimeout(_timeout); if (pageResponse.ok) { contentToProcess = await pageResponse.text(); } else { - console.log(\`[webmention] Live page returned \${pageResponse.status} for \${postUrl}\`); + console.log(\`[webmention] Live page returned \${pageResponse.status} for \${fetchUrl}\`); } } catch (error) { console.log(\`[webmention] Could not fetch live page for \${postUrl}: \${error.message}\`);