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
+2 -13
View File
@@ -3,7 +3,7 @@ import * as schema from '../db/schema.js';
import { eq, and, lte, asc, inArray } from 'drizzle-orm';
import { config } from '../config.js';
import { isFederationRelayEnabled } from './federationOutbox.js';
import { buildFederationHeaders } from './federationAuth.js';
import { buildFederationHeaders, getOurOrigin } from './federationAuth.js';
import { generateSnowflake } from './snowflake.js';
import { getDmMessageWithUser } from '../routes/dm.js';
import { connectionManager } from '../ws/handler.js';
@@ -63,17 +63,6 @@ function getBackoffMs(attempt: number): number {
return BACKOFF_SCHEDULE_MS[Math.max(0, index)] ?? 86_400_000;
}
/**
* Build the origin URL for this instance.
* Uses DOMAIN env var for production, falls back to localhost for dev.
*/
function getOurOrigin(): string {
if (config.domain) {
return `https://${config.domain}`;
}
return `http://localhost:${config.port}`;
}
/**
* Get the effective max upload size from instance settings or config fallback.
*/
@@ -627,7 +616,7 @@ async function runInitialSyncForNewPeers(): Promise<void> {
if (unsyncedPeers.length === 0) return;
const ourOrigin = config.domain ? `https://${config.domain}` : `http://localhost:${config.port}`;
const ourOrigin = getOurOrigin();
for (const peer of unsyncedPeers) {
try {