MCPcopy Create free account
hub / github.com/bytebase/dbhub / resolveHost

Function resolveHost

src/config/env.ts:395–417  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

393 * front DBHub with a reverse proxy or firewall.
394 */
395export 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

Callers 2

mainFunction · 0.85
env.test.tsFile · 0.85

Calls 2

parseCommandLineArgsFunction · 0.85
requireFlagValueFunction · 0.85

Tested by

no test coverage detected