Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions cli/daemon/pubsub/nsq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
53 changes: 53 additions & 0 deletions docs/go/develop/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

<Callout type="warning">

Setting this to `0.0.0.0` exposes NSQ to all network interfaces, allowing external services to connect. Only use this in development environments.

</Callout>

### 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.
Expand Down
53 changes: 53 additions & 0 deletions docs/ts/develop/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

<Callout type="warning">

Setting this to `0.0.0.0` exposes NSQ to all network interfaces, allowing external services to connect. Only use this in development environments.

</Callout>

### 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.
Expand Down