mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-10-27 23:30:55 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
+14
-4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user