refactor(federation): extract getOurOrigin() into shared federationAuth export

Consolidates 4 inline constructions of the instance origin URL into a
single shared function. Removes the private copy in federationWorker
and two ad-hoc domainOrigin variables in federationOutbox.
This commit is contained in:
Jannis Braun
2026-03-26 18:39:42 +01:00
parent 10d4ca0110
commit 22664a6a14
3 changed files with 18 additions and 17 deletions
@@ -1,4 +1,5 @@
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
import { config } from '../config.js';
const DEFAULT_MAX_AGE_MS = 15 * 60 * 1000; // 15 minutes
@@ -122,3 +123,14 @@ export function parseFederationHeaders(
return { origin, timestamp: timestampMs, signature };
}
/**
* Return the canonical origin URL for this instance.
* Uses DOMAIN env var for production, falls back to localhost for dev.
*/
export function getOurOrigin(): string {
if (config.domain) {
return `https://${config.domain}`;
}
return `http://localhost:${config.port}`;
}