fix: show actual bind address in startup logs (#6999)

Co-authored-by: Maks Pikov <mixelburg@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
mixelburg
2026-02-23 23:04:48 +08:00
committed by GitHub
co-authored by Maks Pikov autofix-ci[bot]
parent 49f2633c9b
commit 1de276006c
4 changed files with 38 additions and 15 deletions
+31
View File
@@ -985,3 +985,34 @@ async function commandExists(command) {
}
}
module.exports.commandExists = commandExists;
/**
* Log the server's listening URLs, similar to Vite's dev server output.
* When no hostname is specified (bound to all interfaces), it prints
* localhost plus every non-internal network address.
* @param {string} tag Log tag (e.g. "server", "setup-database")
* @param {number} port Port number
* @param {string} hostname Bound hostname, if any
* @returns {void}
*/
module.exports.printServerUrls = (tag, port, hostname) => {
if (hostname) {
log.info(tag, `Listening on http://${hostname}:${port}`);
return;
}
const { networkInterfaces } = require("os");
const nets = networkInterfaces();
log.info(tag, "Listening on:");
log.info(tag, ` Local: http://localhost:${port}`);
for (const iface of Object.values(nets)) {
for (const addr of iface) {
if (!addr.internal) {
const host = addr.family === "IPv6" ? `[${addr.address}]` : addr.address;
log.info(tag, ` Network: http://${host}:${port}`);
}
}
}
};