fix(gateway): unify listen startup log across bind hosts
This commit is contained in:
@@ -42,4 +42,25 @@ describe("gateway startup log", () => {
|
||||
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("logs all listen endpoints on a single line", () => {
|
||||
const info = vi.fn();
|
||||
const warn = vi.fn();
|
||||
|
||||
logGatewayStartup({
|
||||
cfg: {},
|
||||
bindHost: "127.0.0.1",
|
||||
bindHosts: ["127.0.0.1", "::1"],
|
||||
port: 18789,
|
||||
log: { info, warn },
|
||||
isNixMode: false,
|
||||
});
|
||||
|
||||
const listenMessages = info.mock.calls
|
||||
.map((call) => call[0])
|
||||
.filter((message) => message.startsWith("listening on "));
|
||||
expect(listenMessages).toEqual([
|
||||
`listening on ws://127.0.0.1:18789, ws://[::1]:18789 (PID ${process.pid})`,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,13 +27,8 @@ export function logGatewayStartup(params: {
|
||||
const formatHost = (host: string) => (host.includes(":") ? `[${host}]` : host);
|
||||
const hosts =
|
||||
params.bindHosts && params.bindHosts.length > 0 ? params.bindHosts : [params.bindHost];
|
||||
const primaryHost = hosts[0] ?? params.bindHost;
|
||||
params.log.info(
|
||||
`listening on ${scheme}://${formatHost(primaryHost)}:${params.port} (PID ${process.pid})`,
|
||||
);
|
||||
for (const host of hosts.slice(1)) {
|
||||
params.log.info(`listening on ${scheme}://${formatHost(host)}:${params.port}`);
|
||||
}
|
||||
const listenEndpoints = hosts.map((host) => `${scheme}://${formatHost(host)}:${params.port}`);
|
||||
params.log.info(`listening on ${listenEndpoints.join(", ")} (PID ${process.pid})`);
|
||||
params.log.info(`log file: ${getResolvedLoggerSettings().file}`);
|
||||
if (params.isNixMode) {
|
||||
params.log.info("gateway: running in Nix mode (config managed externally)");
|
||||
|
||||
Reference in New Issue
Block a user