feat: bundle node_modules into the server

This commit is contained in:
Aarnav Tale
2025-03-24 16:08:34 -04:00
parent cac64a6fbe
commit b8d22beb17
6 changed files with 21 additions and 27 deletions
+8 -12
View File
@@ -1,5 +1,4 @@
import { constants, access } from 'node:fs/promises';
import { env, exit, versions } from 'node:process';
import { env, versions } from 'node:process';
import type { UpgradeWebSocket } from 'hono/ws';
import { createHonoServer } from 'react-router-hono-server/node';
import type { WebSocket } from 'ws';
@@ -20,13 +19,6 @@ 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(
@@ -73,14 +65,18 @@ declare module 'react-router' {
interface AppLoadContext extends LoadContext {}
}
export default await createHonoServer({
export default createHonoServer({
useWebSocket: 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
// Only log in development mode
defaultLogger: import.meta.env.DEV,
getLoadContext() {
// TODO: This is the place where we can handle reverse proxy translation
// This is better than doing it in the OIDC client, since we can do it
// for all requests, not just OIDC ones.
return appLoadContext;
},