From 2e67156bfdd38cd380f25acc76fbdc0acf3cd273 Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Sun, 15 Mar 2026 15:00:16 +0100 Subject: [PATCH] fix: resolve AP object URL before authorize_interaction redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Also on fediverse" widget was passing the blog post URL directly to authorize_interaction. If a static file server intercepts the request before Node.js, the remote instance gets HTML instead of AP JSON and shows "Could not connect to the given address". Now fetches /activitypub/api/ap-url first to get the Fedify-served AP object URL (/activitypub/objects/…), which is always routed to Node.js and reliably returns AP JSON. Falls back to the original URL on error. Co-Authored-By: Claude Sonnet 4.6 --- js/fediverse-interact.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/js/fediverse-interact.js b/js/fediverse-interact.js index 4d1375b..7ec927e 100644 --- a/js/fediverse-interact.js +++ b/js/fediverse-interact.js @@ -142,11 +142,23 @@ document.addEventListener("alpine:init", () => { else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); } }, - redirectToInstance(domain) { + async redirectToInstance(domain) { if (this.mode === "share") { window.location.href = `https://${domain}/share?text=${encodeURIComponent(this.targetUrl)}`; } else { - window.location.href = `https://${domain}/authorize_interaction?uri=${encodeURIComponent(this.targetUrl)}`; + // Resolve the blog post URL to its Fedify-served AP object URL. + // Fedify URLs (/activitypub/objects/…) are always routed to Node.js, + // ensuring reliable AP content negotiation when the remote instance + // fetches the URI to process authorize_interaction. + let interactUrl = this.targetUrl; + try { + const resp = await fetch(`/activitypub/api/ap-url?post=${encodeURIComponent(this.targetUrl)}`); + if (resp.ok) { + const data = await resp.json(); + if (data.apUrl) interactUrl = data.apUrl; + } + } catch { /* network error — fall back to blog post URL */ } + window.location.href = `https://${domain}/authorize_interaction?uri=${encodeURIComponent(interactUrl)}`; } }, }));