Skip to content

feat: add HTTP_HOST to bind metrics/health server to a specific interface#168

Open
lystopad wants to merge 1 commit into
lidofinance:developfrom
lystopad:feature/lystopad/http-host
Open

feat: add HTTP_HOST to bind metrics/health server to a specific interface#168
lystopad wants to merge 1 commit into
lidofinance:developfrom
lystopad:feature/lystopad/http-host

Conversation

@lystopad
Copy link
Copy Markdown

Description

Adds a new optional HTTP_HOST environment variable that lets operators bind the metrics/health HTTP server to a specific network interface (e.g. 127.0.0.1 for loopback-only, or a private interface) instead of having Node.js listen on all interfaces by default.

This is useful when the ejector runs on a host that should not expose its metrics/health endpoints publicly — operators can scope the server to a private interface and rely on a reverse proxy or local scraper for access.

Behavior

  • HTTP_HOST is optional. When unset, behavior is unchanged: Node.js listens on all interfaces (:: on IPv6-capable hosts, otherwise 0.0.0.0).
  • Accepts IPv4 (e.g. 127.0.0.1, 0.0.0.0) or IPv6 (e.g. ::1, ::) addresses.
  • Only listen(HTTP_PORT, HTTP_HOST) is called when HTTP_HOST is set; otherwise the original listen(HTTP_PORT) call is preserved, so default Node.js binding semantics are kept identical.

Files changed

  • src/services/config/service.ts — parse HTTP_HOST (optional string, no default).
  • src/services/http-handler/service.ts — pass host to listen() only when defined.
  • sample.env, sample.infra.env — commented-out example with IPv4/IPv6 guidance.
  • README.md — new row in the env var table documenting the variable and its default.

Related Issue/Task

No related issue. Searched open issues for HTTP_HOST, bind, interface, 0.0.0.0 — no prior art.

How Has This Been Tested?

  • Local tests (e.g., yarn test)
  • Manual testing (described below)
  • Not tested

Manual reasoning rather than runtime verification: the change is minimal and the conditional preserves the exact original .listen(HTTP_PORT) call when HTTP_HOST is unset, so existing configurations are unaffected. The new branch passes both port and host to Node's net.Server.listen(port, host), which is the documented signature for binding to a specific interface.

Happy to add an integration test for the bind address if maintainers prefer.

Checklist

  • Documentation updated (README env var table + sample envs)
  • New tests added (not added — no existing tests cover http-handler bind; can add on request)

…face

Allows operators to bind the HTTP server to a private interface (e.g.
127.0.0.1) instead of having Node.js listen on all interfaces by default,
reducing exposure of the metrics and health endpoints.

When HTTP_HOST is unset, behavior is unchanged: Node.js listens on all
interfaces (:: on IPv6-capable hosts, otherwise 0.0.0.0). HTTP_HOST
accepts IPv4 or IPv6 addresses.

Co-Authored-By: Claude
@lystopad lystopad requested a review from a team as a code owner May 20, 2026 13:29
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.

1 participant