[object Object]

← back to Interiordesignershowroom

fix(server): graceful listen error handler + honest HOST bind (was unhandled crash on EADDRINUSE + log lied about bind host)

c686c5d31a7a7d083f96ff06b985680a4b4fbcea · 2026-08-03 12:22:26 -0700 · Steve Abrams

Files touched

Diff

commit c686c5d31a7a7d083f96ff06b985680a4b4fbcea
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon Aug 3 12:22:26 2026 -0700

    fix(server): graceful listen error handler + honest HOST bind (was unhandled crash on EADDRINUSE + log lied about bind host)
---
 server.js | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/server.js b/server.js
index 2a6abcc..29fc3ed 100644
--- a/server.js
+++ b/server.js
@@ -696,4 +696,14 @@ app.use(require('./routes/admin'));
 app.use((_req, res) => res.status(404).send(layout({ title: 'Not found', body: '<section><h1>Not found</h1><p><a href="/">Back to the showroom →</a></p></section>' })));
 app.use((err, _req, res, _next) => { console.error(err); res.status(500).send(layout({ title: 'Error', body: '<section><h1>Something went wrong</h1></section>' })); });
 
-app.listen(PORT, () => console.log(`[IDS] listening on http://127.0.0.1:${PORT}`));
+// Bind to loopback by default (matches the log + keeps the app behind the proxy rather
+// than exposed on every interface). Override with HOST=0.0.0.0 if a remote proxy needs it.
+const HOST = process.env.HOST || '127.0.0.1';
+const server = app.listen(PORT, HOST, () => console.log(`[IDS] listening on http://${HOST}:${PORT}`));
+// Fail loud + clean on a listen error instead of an unhandled 'error' event crash.
+server.on('error', (err) => {
+  if (err.code === 'EADDRINUSE') console.error(`[IDS] port ${PORT} already in use — another instance running? (pm2 list)`);
+  else if (err.code === 'EACCES') console.error(`[IDS] permission denied binding ${HOST}:${PORT}`);
+  else console.error('[IDS] server listen error:', err);
+  process.exit(1);
+});

← 27b1775 security: full script-src 'self' CSP on public (delegated al  ·  back to Interiordesignershowroom  ·  GA4: inject gtag.js (G-DH9G5HL7YJ) into layout head — analyt bc6f4d9 →