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 17:04:48 +02:00
committed by GitHub
parent 49f2633c9b
commit 1de276006c
4 changed files with 38 additions and 15 deletions

View File

@@ -110,6 +110,7 @@ const {
shake256, shake256,
SHAKE256_LENGTH, SHAKE256_LENGTH,
allowDevAllOrigin, allowDevAllOrigin,
printServerUrls,
} = require("./util-server"); } = require("./util-server");
log.debug("server", "Importing Notification"); log.debug("server", "Importing Notification");
@@ -1741,11 +1742,7 @@ let needSetup = false;
await server.start(); await server.start();
server.httpServer.listen(port, hostname, async () => { server.httpServer.listen(port, hostname, async () => {
if (hostname) { printServerUrls("server", port, hostname);
log.info("server", `Listening on ${hostname}:${port}`);
} else {
log.info("server", `Listening on ${port}`);
}
await startMonitors(); await startMonitors();
// Put this here. Start background jobs after the db and server is ready to prevent clear up during db migration. // Put this here. Start background jobs after the db and server is ready to prevent clear up during db migration.

View File

@@ -4,7 +4,7 @@ const expressStaticGzip = require("express-static-gzip");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const Database = require("./database"); const Database = require("./database");
const { allowDevAllOrigin } = require("./util-server"); const { allowDevAllOrigin, printServerUrls } = require("./util-server");
const mysql = require("mysql2/promise"); const mysql = require("mysql2/promise");
/** /**
@@ -307,9 +307,8 @@ class SetupDatabase {
}); });
tempServer = app.listen(port, hostname, () => { tempServer = app.listen(port, hostname, () => {
log.info("setup-database", `Starting Setup Database on ${port}`); log.info("setup-database", "Starting Setup Database");
let domain = hostname ? hostname : "localhost"; printServerUrls("setup-database", port, hostname);
log.info("setup-database", `Open http://${domain}:${port} in your browser`);
log.info("setup-database", "Waiting for user action..."); log.info("setup-database", "Waiting for user action...");
}); });
}); });

View File

@@ -985,3 +985,34 @@ async function commandExists(command) {
} }
} }
module.exports.commandExists = commandExists; 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}`);
}
}
}
};

View File

@@ -1,6 +1,6 @@
const express = require("express"); const express = require("express");
const http = require("node:http"); const http = require("node:http");
const { log } = require("../../src/util"); const { printServerUrls } = require("../util-server");
/** /**
* SimpleMigrationServer * SimpleMigrationServer
@@ -64,11 +64,7 @@ class SimpleMigrationServer {
return new Promise((resolve) => { return new Promise((resolve) => {
this.server.listen(port, hostname, () => { this.server.listen(port, hostname, () => {
if (hostname) { printServerUrls("migration", port, hostname);
log.info("migration", `Migration server is running on http://${hostname}:${port}`);
} else {
log.info("migration", `Migration server is running on http://localhost:${port}`);
}
resolve(); resolve();
}); });
}); });