diff --git a/cli/daemon/pubsub/nsq.go b/cli/daemon/pubsub/nsq.go index b4f589415e..342514ff55 100644 --- a/cli/daemon/pubsub/nsq.go +++ b/cli/daemon/pubsub/nsq.go @@ -56,11 +56,33 @@ func (n *NSQDaemon) Start() error { n.Opts.LogLevel = nsqd.LOG_WARN n.Opts.Logger = &logAdapter{"nsqd"} - // Take the default address options and scope down to localhost (to prevent firewall warnings / permission requests) - // then set the port to 0 to allow any port to be used which is free - n.Opts.TCPAddress = "127.0.0.1:0" - n.Opts.HTTPAddress = "127.0.0.1:0" - n.Opts.HTTPSAddress = "127.0.0.1:0" + // Check for environment variables to configure NSQ bind addresses + // This allows external services to connect to NSQ during local development + // ENCORE_NSQ_TCP_ADDRESS: TCP address for message publishing (default: 127.0.0.1:0) + // ENCORE_NSQ_HTTP_ADDRESS: HTTP address for admin/stats (default: 127.0.0.1:0) + // Use 0.0.0.0 to bind to all interfaces, or a specific IP:port + if tcpAddr := os.Getenv("ENCORE_NSQ_TCP_ADDRESS"); tcpAddr != "" { + n.Opts.TCPAddress = tcpAddr + } else { + // Default to localhost to prevent firewall warnings / permission requests + // then set the port to 0 to allow any port to be used which is free + n.Opts.TCPAddress = "127.0.0.1:0" + } + + if httpAddr := os.Getenv("ENCORE_NSQ_HTTP_ADDRESS"); httpAddr != "" { + n.Opts.HTTPAddress = httpAddr + } else { + // Default to localhost + n.Opts.HTTPAddress = "127.0.0.1:0" + } + + // HTTPS address follows HTTP address if not explicitly set + if httpsAddr := os.Getenv("ENCORE_NSQ_HTTPS_ADDRESS"); httpsAddr != "" { + n.Opts.HTTPSAddress = httpsAddr + } else { + n.Opts.HTTPSAddress = "127.0.0.1:0" + } + n.Opts.MaxMsgSize = 10 * 1024 * 1024 // 10MB } nsq, err := nsqd.New(n.Opts) diff --git a/docs/go/develop/env-vars.md b/docs/go/develop/env-vars.md index ad12629903..f29dda0bdc 100644 --- a/docs/go/develop/env-vars.md +++ b/docs/go/develop/env-vars.md @@ -67,6 +67,59 @@ Overrides the listen address for the object storage service endpoint. export ENCORE_OBJECTSTORAGE_LISTEN_ADDR=localhost:9402 ``` +### ENCORE_NSQ_TCP_ADDRESS + +Overrides the TCP bind address for the NSQ daemon used for PubSub message publishing. + +**Default:** `127.0.0.1:0` (localhost with auto-assigned port) + +**Format:** Network address (e.g., `0.0.0.0:4150` or `127.0.0.1:4150`) + +**Example:** + +```bash +# Expose NSQ on all interfaces with a fixed port +export ENCORE_NSQ_TCP_ADDRESS=0.0.0.0:4150 +encore run +``` + + + +Setting this to `0.0.0.0` exposes NSQ to all network interfaces, allowing external services to connect. Only use this in development environments. + + + +### ENCORE_NSQ_HTTP_ADDRESS + +Overrides the HTTP bind address for the NSQ daemon admin/stats endpoint. + +**Default:** `127.0.0.1:0` (localhost with auto-assigned port) + +**Format:** Network address (e.g., `0.0.0.0:4151` or `127.0.0.1:4151`) + +**Example:** + +```bash +# Expose NSQ HTTP admin interface on all interfaces +export ENCORE_NSQ_HTTP_ADDRESS=0.0.0.0:4151 +encore run +``` + +### ENCORE_NSQ_HTTPS_ADDRESS + +Overrides the HTTPS bind address for the NSQ daemon (if HTTPS is enabled). + +**Default:** `127.0.0.1:0` (localhost with auto-assigned port) + +**Format:** Network address + +**Example:** + +```bash +export ENCORE_NSQ_HTTPS_ADDRESS=0.0.0.0:4152 +encore run +``` + ## Advanced Development These variables are primarily useful for advanced development scenarios, such as contributing to Encore itself or using custom builds. diff --git a/docs/ts/develop/env-vars.md b/docs/ts/develop/env-vars.md index 752f03a157..13f85267aa 100644 --- a/docs/ts/develop/env-vars.md +++ b/docs/ts/develop/env-vars.md @@ -67,6 +67,59 @@ Overrides the listen address for the object storage service endpoint. export ENCORE_OBJECTSTORAGE_LISTEN_ADDR=localhost:9402 ``` +### ENCORE_NSQ_TCP_ADDRESS + +Overrides the TCP bind address for the NSQ daemon used for PubSub message publishing. + +**Default:** `127.0.0.1:0` (localhost with auto-assigned port) + +**Format:** Network address (e.g., `0.0.0.0:4150` or `127.0.0.1:4150`) + +**Example:** + +```bash +# Expose NSQ on all interfaces with a fixed port +export ENCORE_NSQ_TCP_ADDRESS=0.0.0.0:4150 +encore run +``` + + + +Setting this to `0.0.0.0` exposes NSQ to all network interfaces, allowing external services to connect. Only use this in development environments. + + + +### ENCORE_NSQ_HTTP_ADDRESS + +Overrides the HTTP bind address for the NSQ daemon admin/stats endpoint. + +**Default:** `127.0.0.1:0` (localhost with auto-assigned port) + +**Format:** Network address (e.g., `0.0.0.0:4151` or `127.0.0.1:4151`) + +**Example:** + +```bash +# Expose NSQ HTTP admin interface on all interfaces +export ENCORE_NSQ_HTTP_ADDRESS=0.0.0.0:4151 +encore run +``` + +### ENCORE_NSQ_HTTPS_ADDRESS + +Overrides the HTTPS bind address for the NSQ daemon (if HTTPS is enabled). + +**Default:** `127.0.0.1:0` (localhost with auto-assigned port) + +**Format:** Network address + +**Example:** + +```bash +export ENCORE_NSQ_HTTPS_ADDRESS=0.0.0.0:4152 +encore run +``` + ## Logging Configuration These variables control the logging behavior for TypeScript applications.