()
| 393 | * front DBHub with a reverse proxy or firewall. |
| 394 | */ |
| 395 | export function resolveHost(): { host: string; source: string } { |
| 396 | const args = parseCommandLineArgs(); |
| 397 | |
| 398 | // 1. Command line argument has highest priority. |
| 399 | const cliHost = requireFlagValue("host", args, "127.0.0.1"); |
| 400 | if (cliHost !== undefined) { |
| 401 | return { host: cliHost, source: "command line argument" }; |
| 402 | } |
| 403 | |
| 404 | // 2. Environment variable (trimmed; empty or whitespace-only is unset) |
| 405 | // Using DBHUB_HOST rather than generic HOST to avoid collisions — HOST is |
| 406 | // set by default in csh/tcsh, some CI systems, and Docker base images |
| 407 | // (often to the machine hostname), which would silently redirect binds. |
| 408 | // Trimming matches the --host flag's validation so `DBHUB_HOST=" "` |
| 409 | // doesn't get handed to listen() and fail with an obscure bind error. |
| 410 | const envHost = process.env.DBHUB_HOST?.trim(); |
| 411 | if (envHost) { |
| 412 | return { host: envHost, source: "environment variable" }; |
| 413 | } |
| 414 | |
| 415 | // 3. Default: bind all interfaces |
| 416 | return { host: "0.0.0.0", source: "default" }; |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Resolve the list of additional hostnames the HTTP transport accepts in the |
no test coverage detected