feat: add host binding configuration option#920
Conversation
📝 WalkthroughWalkthroughThis PR adds support for configuring the HTTP server bind address via a new ChangesHost Address Configuration
🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/appconf/json_config.go (1)
37-37: ⚡ Quick winConsider defaulting
HostinsetDefaults()for config-layer consistency.Right now the schema advertises a
0.0.0.0default, but JSON config defaults do not set it explicitly. Centralizing that default insetDefaults()keeps behavior/documentation aligned across consumers.♻️ Suggested tweak
func (j *JSONConfig) setDefaults() { if j.Port == 0 { j.Port = 4000 } + if j.Host == "" { + j.Host = "0.0.0.0" + } if j.Env == "" { j.Env = "development" }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/appconf/json_config.go` at line 37, The config struct's Host field is advertised to default to "0.0.0.0" but that default isn't being applied in setDefaults(); update the setDefaults() function to explicitly set Host = "0.0.0.0" when Host is empty (or zero-valued) so JSON-configured instances align with the schema/documentation—look for the Host field on the config struct and the setDefaults() method to add this conditional assignment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/api/app.go`:
- Around line 153-157: The local variable host defined in app.go (host :=
cfg.Host with fallback to "0.0.0.0") is never used which causes a compile error;
update the server startup to use that host variable instead of cfg.Host (e.g.,
replace any direct use of cfg.Host when constructing the server address/Addr
with the local host variable), or alternatively remove the unused host variable
and implement the fallback directly where the server address is built so the
effective host value is used by the http.Server/start call.
---
Nitpick comments:
In `@internal/appconf/json_config.go`:
- Line 37: The config struct's Host field is advertised to default to "0.0.0.0"
but that default isn't being applied in setDefaults(); update the setDefaults()
function to explicitly set Host = "0.0.0.0" when Host is empty (or zero-valued)
so JSON-configured instances align with the schema/documentation—look for the
Host field on the config struct and the setDefaults() method to add this
conditional assignment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 33c06213-6379-4f77-aa5b-5fc8eaed1b20
📒 Files selected for processing (6)
cmd/api/app.gocmd/api/main.goconfig.example.jsonconfig.schema.jsoninternal/appconf/config.gointernal/appconf/json_config.go
fix : host reference
8d1c11c to
f46490b
Compare
|
|
Shall I update the appropriate comments and documentation for this addition ? |



Adds a
hostfield to the configuration file to control the server's binding address, allowing operators to restrict the server to a specific interface (e.g.127.0.0.1) instead of binding to all interfaces (0.0.0.0).The field is optional and defaults to
0.0.0.0to preserve existing behavior.Fixes #896
@aaronbrethorst
@chrisls121
Summary by CodeRabbit
-hostcommand-line flag andhostconfiguration field, enabling configuration of the server bind address.