From 0c23f67708b286d1e923e4d93aaba238edf66bb3 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 1 Sep 2023 11:52:53 +0200 Subject: [PATCH] Streaming fe server: bind to 0.0.0.0 in prod (#9115) Fixing this problem with fly deploys ![image](https://github.com/redwoodjs/redwood/assets/30793/f2d6d342-854f-4e03-92a5-199d07e22ae8) But this isn't specific to Fly. Docker deploys in general usually require you to bind to 0.0.0.0. We already do this for regular non-streaming deploys. For example here https://github.com/redwoodjs/redwood/blob/8d0ab16aa1c39f1526e4213211608805735f6974/packages/cli/src/commands/serveBothHandler.js#L137 --- packages/vite/src/runFeServer.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/runFeServer.ts b/packages/vite/src/runFeServer.ts index 3954cb5e6f9d..69a726432290 100644 --- a/packages/vite/src/runFeServer.ts +++ b/packages/vite/src/runFeServer.ts @@ -119,10 +119,25 @@ export async function runFeServer() { app.get(expressPathDef, routeHandler) } - app.listen(rwConfig.web.port) - console.log( - `Started production FE server on http://localhost:${rwConfig.web.port}` + const server = app.listen( + rwConfig.web.port, + process.env.NODE_ENV === 'production' ? '0.0.0.0' : '::' ) + + server.on('listening', () => { + let addressDetails = '' + const address = server.address() + + if (typeof address === 'string') { + addressDetails = `(${address})` + } else if (address && typeof address === 'object') { + addressDetails = `(${address.address}:${address.port})` + } + + console.log( + `Started production FE server on http://localhost:${rwConfig.web.port} ${addressDetails}` + ) + }) } runFeServer()