From ffae263bae585c348ebd56614c725d16de2ebec6 Mon Sep 17 00:00:00 2001 From: Melvin Carvalho Date: Tue, 9 Jun 2026 21:18:19 +0200 Subject: [PATCH] fix: align runtime port fallbacks with canonical 4443 default (#477) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #245 changed the declared default port from 3000 → 4443 in src/config.js (April 2026), but four runtime fallbacks still read `port || 3000`. Programmatic embedders, tests that call startServer() with no port, and the package's main entry (src/index.js when PORT env is unset) all landed on 3000 instead of 4443 — an inconsistency that hid behind any caller that happened to pass a port. Fix uses the author's preferred 'one source of truth' shape from the issue body: import `defaults` from ./config.js and reference `defaults.port` so future port changes only touch config.js. - src/server.js:879 options.port || 3000 → || defaults.port - src/server.js:1224 options.port || 3000 → || defaults.port - src/server.js:1235 startServer(port=3000) → port=defaults.port - src/index.js:3 process.env.PORT || 3000 → || defaults.port Scope discipline: port only. The adjacent '0.0.0.0' host literals stay as-is — they aren't part of this issue and a separate fix can align them if desired. Verification: grep -nE '3000' src/server.js src/index.js → none Full test suite: 917/917 passing No existing test depended on 3000 as the port default (the only 3000 references in test/ are millisecond timeouts; tests use getAvailablePort() for actual port binding). Closes #477. --- src/index.js | 3 ++- src/server.js | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 5bd7d8b9..00915c43 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ import { startServer } from './server.js'; +import { defaults } from './config.js'; -const PORT = process.env.PORT || 3000; +const PORT = process.env.PORT || defaults.port; const HOST = process.env.HOST || '0.0.0.0'; startServer(PORT, HOST).then(() => { diff --git a/src/server.js b/src/server.js index 8459524f..05b03d8a 100644 --- a/src/server.js +++ b/src/server.js @@ -23,6 +23,7 @@ import { AccessMode } from './wac/parser.js'; import { registerNostrRelay } from './nostr/relay.js'; import { createPayHandler, isPayRequest } from './handlers/pay.js'; import { activityPubPlugin, getActorHandler } from './ap/index.js'; +import { defaults } from './config.js'; import { remoteStoragePlugin } from './remotestorage.js'; import { dbPlugin } from './db/index.js'; import { mcpPlugin } from './mcp/index.js'; @@ -875,7 +876,7 @@ export function createServer(options = {}) { // Determine base URL for pod URIs const protocol = options.ssl ? 'https' : 'http'; const host = options.host === '0.0.0.0' ? 'localhost' : (options.host || 'localhost'); - const port = options.port || 3000; + const port = options.port || defaults.port; const baseUrl = idpIssuer?.replace(/\/$/, '') || `${protocol}://${host}:${port}`; const issuer = idpIssuer || `${baseUrl}/`; @@ -1220,7 +1221,7 @@ export function createServer(options = {}) { const dataRoot = options.root || process.env.DATA_ROOT || './data'; const protocol = options.ssl ? 'https' : 'http'; // Use configured port, or default; actual URL will be localhost - const port = options.port || 3000; + const port = options.port || defaults.port; const baseUrl = `${protocol}://localhost:${port}`; startFileWatcher(dataRoot, baseUrl); } @@ -1231,7 +1232,7 @@ export function createServer(options = {}) { /** * Start the server */ -export async function startServer(port = 3000, host = '0.0.0.0') { +export async function startServer(port = defaults.port, host = '0.0.0.0') { const server = createServer(); try {