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 <noreply@anthropic.com>
This commit is contained in:
Sven
2026-03-18 17:23:12 +01:00
parent c1197608ef
commit 1f4f55d4fc

View File

@@ -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}\`);