fix: allow hostname passthrough for hono node

This commit is contained in:
Aarnav Tale 2025-03-24 13:57:04 -04:00
parent 03acebb23e
commit 5918d0e501
7 changed files with 55 additions and 14 deletions

View file

@ -1,4 +1,5 @@
import { env, versions } from 'node:process';
import { constants, access } from 'node:fs/promises';
import { env, exit, versions } from 'node:process';
import type { UpgradeWebSocket } from 'hono/ws';
import { createHonoServer } from 'react-router-hono-server/node';
import type { WebSocket } from 'ws';
@ -19,6 +20,13 @@ declare global {
// MARK: Side-Effects
// This module contains a side-effect because everything running here
// exists for the lifetime of the process, making it appropriate.
try {
await access('./node_modules/react-router', constants.F_OK | constants.R_OK);
} catch {
log.error('server', 'Cannot locate `node_modules`, please install them');
exit(1);
}
log.info('server', 'Running Node.js %s', versions.node);
configureLogger(env[envVariables.debugLog]);
const config = await loadConfig(
@ -67,7 +75,9 @@ declare module 'react-router' {
export default await createHonoServer({
useWebSocket: true,
// overrideGlobalObjects: true,
overrideGlobalObjects: true,
port: config.server.port,
hostname: config.server.host,
getLoadContext(c, { build, mode }) {
// This is the place where we can handle reverse proxy translation
@ -89,6 +99,6 @@ export default await createHonoServer({
}
},
listeningListener(info) {
console.log(`Server is listening on http://localhost:${info.port}`);
log.info('server', 'Running on %s:%s', info.address, info.port);
},
});