Files
OmniRoute/bin/cli/utils/serverHost.mjs
Yahoo 2098ba3848 fix(cli): ignore non-Windows HOSTNAME when binding server (#10557)
* fix(cli): ignore non-Windows HOSTNAME when binding server

* chore(changelog): assign PR number
2026-08-17 08:09:19 -03:00

27 lines
883 B
JavaScript

import { hostname, platform } from "node:os";
/**
* Resolve the bind host passed to the standalone Next.js server.
*
* HOSTNAME is a standard shell variable on Unix-like systems, so only the
* dedicated OmniRoute variable is treated as configuration there. Windows
* keeps the legacy HOSTNAME fallback for compatibility with existing .env
* files, while still ignoring the OS-reported machine name.
*
* @param {NodeJS.ProcessEnv} [env]
* @param {NodeJS.Platform} [runtimePlatform]
* @param {string} [machineHostname]
* @returns {string}
*/
export function resolveServerHost(
env = process.env,
runtimePlatform = platform(),
machineHostname = hostname()
) {
if (env.OMNIROUTE_SERVER_HOST) return env.OMNIROUTE_SERVER_HOST;
if (runtimePlatform === "win32" && env.HOSTNAME && env.HOSTNAME !== machineHostname) {
return env.HOSTNAME;
}
return "0.0.0.0";
}