Skip to content

feat: add HOST environment variable for configurable bind address#360

Open
mjfork wants to merge 2 commits intositeboon:mainfrom
mjfork:feature/host-binding
Open

feat: add HOST environment variable for configurable bind address#360
mjfork wants to merge 2 commits intositeboon:mainfrom
mjfork:feature/host-binding

Conversation

@mjfork
Copy link

@mjfork mjfork commented Jan 31, 2026

Summary

  • Add HOST environment variable to configure which host/IP the servers bind to
  • Default to 0.0.0.0 (all interfaces) for backward compatibility
  • Update both Express server and Vite dev server to respect the HOST setting

Fixes #359

Changes

  • .env.example: Added HOST environment variable with documentation
  • server/index.js: Use HOST env var instead of hardcoded '0.0.0.0'
  • vite.config.js: Added host option to Vite server config

Test plan

  • Set HOST=127.0.0.1 and verify server only listens on localhost
  • Leave HOST unset and verify server listens on all interfaces (default behavior)
  • Verify both backend server and Vite dev server respect the HOST setting

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Server and dev tooling now respect a configurable host and port via environment variables, making it easier to change the network interface without code edits.
    • Local URLs shown in logs and dev proxies normalize a bind-all address to "localhost" for clearer, user-friendly links.

✏️ Tip: You can customize this high-level summary in your review settings.

Allow users to specify which host/IP address the servers should bind to
via the HOST environment variable. Defaults to 0.0.0.0 (all interfaces)
to maintain backward compatibility.

This enables users to restrict the server to localhost only (127.0.0.1)
for security purposes or bind to a specific network interface.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 31, 2026

Walkthrough

Adds a configurable HOST environment variable (default 0.0.0.0) and updates server and Vite dev server startup/logging to use that value, mapping 0.0.0.0 to localhost for display purposes.

Changes

Cohort / File(s) Summary
Environment Example
\.env.example
Added HOST entry with default 0.0.0.0 and comments explaining binding behavior and localhost mapping.
Server & Dev Server
server/index.js, vite.config.js
Read HOST from environment (default 0.0.0.0); compute a display/proxy host (localhost when binding to 0.0.0.0); use HOST for listen/serve and update logs/proxy targets accordingly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nibble bytes and sniff the net,
HOST set free — no longer met,
Bind where you wish, near or far,
I hop between localhost and star,
Cheers from a rabbit, code and carrot char! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main change: adding a HOST environment variable for configurable bind address, which matches the primary objective of the changeset.
Linked Issues check ✅ Passed All requirements from issue #359 are met: HOST env var added to .env.example with documentation, server/index.js updated to use HOST, and vite.config.js configured to respect HOST settings.
Out of Scope Changes check ✅ Passed All changes are directly related to the HOST environment variable feature. The DISPLAY_HOST logic and proxy configuration enhancements align with the objective of making the feature functional and user-friendly.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
vite.config.js (1)

11-22: ⚠️ Potential issue | 🟠 Major

Proxy targets ignore HOST and can break non-local binds.
If HOST is set to a specific interface (e.g., 192.168.1.100), the backend binds only there, but the Vite proxy still targets localhost, which will fail. Use a derived proxyHost that falls back to localhost only when HOST=0.0.0.0.

🐛 Proposed fix
 export default defineConfig(({ command, mode }) => {
   // Load env file based on `mode` in the current working directory.
   const env = loadEnv(mode, process.cwd(), '')
+  const host = env.HOST || '0.0.0.0'
+  const proxyHost = host === '0.0.0.0' ? 'localhost' : host
   
   return {
     plugins: [react()],
     server: {
-      host: env.HOST || '0.0.0.0',
+      host,
       port: parseInt(env.VITE_PORT) || 5173,
       proxy: {
-        '/api': `http://localhost:${env.PORT || 3001}`,
+        '/api': `http://${proxyHost}:${env.PORT || 3001}`,
         '/ws': {
-          target: `ws://localhost:${env.PORT || 3001}`,
+          target: `ws://${proxyHost}:${env.PORT || 3001}`,
           ws: true
         },
         '/shell': {
-          target: `ws://localhost:${env.PORT || 3001}`,
+          target: `ws://${proxyHost}:${env.PORT || 3001}`,
           ws: true
         }
       }
     },
🧹 Nitpick comments (1)
server/index.js (1)

1801-1829: Consider a user-friendly URL when HOST is 0.0.0.0.
Line 1829 will print http://0.0.0.0:PORT, which isn’t a connectable URL for most users. A display host (e.g., localhost when bound to all interfaces) avoids confusion.

♻️ Suggested tweak
-const HOST = process.env.HOST || '0.0.0.0';
+const HOST = process.env.HOST || '0.0.0.0';
+const DISPLAY_HOST = HOST === '0.0.0.0' ? 'localhost' : HOST;
...
-            console.log(`${c.info('[INFO]')} Server URL:  ${c.bright('http://' + HOST + ':' + PORT)}`);
+            console.log(`${c.info('[INFO]')} Server URL:  ${c.bright('http://' + DISPLAY_HOST + ':' + PORT)}`);

When HOST is set to a specific interface (e.g., 192.168.1.100), the Vite
proxy needs to connect to that same host, not localhost. This fix:

- Adds proxyHost logic that uses localhost when HOST=0.0.0.0, otherwise
  uses the specific HOST value for proxy targets
- Adds DISPLAY_HOST to show a user-friendly URL in console output
  (0.0.0.0 isn't a connectable address)

Addresses CodeRabbit review feedback.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@blackmammoth blackmammoth self-assigned this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Allow configurable HOST/IP binding

2 participants