From c1f9d64401a86df9b74afa432c2beff309657ad9 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 17 Mar 2026 11:58:35 +0100 Subject: [PATCH] fix(patches): rewrite livefetch URL to localhost and add timeout The webmention sender livefetch patch was fetching the public HTTPS URL which hangs in the jailed setup (port 443 is on the nginx jail). Rewrite to localhost like all other internal-fetch patches, and add a 15s AbortController timeout. Bump reset-stale migration to v5 so posts incorrectly marked as sent with 0/0/0 get retried. Co-Authored-By: Claude Opus 4.6 --- scripts/patch-webmention-sender-livefetch.mjs | 20 ++++++++++++++++--- .../patch-webmention-sender-reset-stale.mjs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/patch-webmention-sender-livefetch.mjs b/scripts/patch-webmention-sender-livefetch.mjs index 382c7fdd..a23cbca8 100644 --- a/scripts/patch-webmention-sender-livefetch.mjs +++ b/scripts/patch-webmention-sender-livefetch.mjs @@ -40,16 +40,30 @@ const originalBlock = ` // If no content, try fetching the published page 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 localhost for jailed setups where the server + // can't reach its own public HTTPS URL. let contentToProcess = ""; try { - const pageResponse = await fetch(postUrl); + const _internalBase = (() => { + if (process.env.INTERNAL_FETCH_URL) return process.env.INTERNAL_FETCH_URL.replace(/\\/+$/, ""); + const port = process.env.PORT || "3000"; + return \`http://localhost:\${port}\`; + })(); + const _publicBase = (process.env.PUBLICATION_URL || process.env.SITE_URL || "").replace(/\\/+$/, ""); + const fetchUrl = (_publicBase && postUrl.startsWith(_publicBase)) + ? _internalBase + postUrl.slice(_publicBase.length) + : postUrl; + const _ac = new AbortController(); + const _timeout = setTimeout(() => _ac.abort(), 15000); + 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 \${postUrl}: \${error.message}\`); + console.log(\`[webmention] Could not fetch live page for \${postUrl}: \${error.message}\`); } // Fall back to stored content if live page is unavailable diff --git a/scripts/patch-webmention-sender-reset-stale.mjs b/scripts/patch-webmention-sender-reset-stale.mjs index 04b0caab..fbf710a6 100644 --- a/scripts/patch-webmention-sender-reset-stale.mjs +++ b/scripts/patch-webmention-sender-reset-stale.mjs @@ -9,7 +9,7 @@ import { MongoClient } from "mongodb"; import config from "../indiekit.config.mjs"; -const MIGRATION_ID = "webmention-sender-reset-stale-v4"; +const MIGRATION_ID = "webmention-sender-reset-stale-v5"; const mongodbUrl = config.application?.mongodbUrl; if (!mongodbUrl) {