From 21dbe2338df677f4ad88816355a599060e87576a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Krzeslak?= Date: Mon, 26 Oct 2026 21:55:13 +0100 Subject: [PATCH] fix: centralize server URL construction for eden client Extract server URL into a dedicated serverUrl() helper with explicit fallbacks for hostname and port. This addresses the review finding that app.server?.hostname and app.server?.port may be undefined at creation time (Elysia's Server type is a union that doesn't expose these directly). Co-Authored-By: Claude Code --- src/index.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index d66d3eac..44007910 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -78,12 +78,22 @@ if (process.env.NODE_ENV !== "production") { app.listen(process.env.PORT || 3000); -console.log(`🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}${WEBROOT}`); +/** + * Construct the server URL with explicit fallbacks for hostname and port. app.server?.hostname and + * app.server?.port may be undefined (Elysia's Server type is a union that doesn't expose these + * directly), so we fall back to "localhost" and the configured/default port respectively. + */ +const serverUrl = () => { + const s = app.server; + const host = s?.hostname ?? "localhost"; + const port = s?.port ?? (process.env.PORT || 3000); + return `http://${host}:${port}${WEBROOT}`; +}; + +console.log(`🦊 Elysia is running at ${serverUrl()}`); // Create an Eden client for type-safe server-side API access and testing. -export const eden = createEdenClient( - `http://${app.server?.hostname ?? "localhost"}:${app.server?.port ?? (process.env.PORT || 3000)}`, -) as EdenAppClient; +export const eden = createEdenClient(serverUrl()) as EdenAppClient; const MILLISECONDS_PER_HOUR = 60 * 60 * 1000; const autoDeleteIntervalMs = AUTO_DELETE_EVERY_N_HOURS * MILLISECONDS_PER_HOUR;