/** * Patch @indiekit/endpoint-auth to remove its /.well-known/oauth-authorization-server * handler so the Mastodon router's handler (with correct /oauth/authorize endpoint) * takes precedence. endpoint-auth registers first in Express, winning over the * Mastodon router — this removes the conflicting registration. */ import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { join, dirname } from "node:path"; const __dirname = dirname(fileURLToPath(import.meta.url)); const pkg = join(__dirname, "../node_modules/@indiekit/endpoint-auth/index.js"); let src = readFileSync(pkg, "utf-8"); const MARKER = "// patch-mastodon-well-known: removed"; if (src.includes(MARKER)) { console.log("[patch-mastodon-well-known] Already applied"); process.exit(0); } const OLD = `router.get("/oauth-authorization-server", metadataController);`; const NEW = `${MARKER}`; if (!src.includes(OLD)) { console.error("[patch-mastodon-well-known] Target line not found — check endpoint-auth version"); process.exit(1); } src = src.replace(OLD, NEW); writeFileSync(pkg, src, "utf-8"); console.log("[patch-mastodon-well-known] Removed endpoint-auth well-known handler; Mastodon router takes over");