Skip to content

Commit

Permalink
Fix port 0 logging (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBrimble committed Sep 20, 2022
1 parent 1c8b804 commit 9265fa4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/http-server/src/index.ts
Expand Up @@ -482,9 +482,12 @@ export async function startServer<Plugins extends HTTPPluginSignatures>(
const protocol = httpsEnabled ? "https" : "http";
const accessibleHosts =
host && host !== "0.0.0.0" ? [host] : getAccessibleHosts(true);
log.info(`Listening on ${host ?? ""}:${port}`);
const address = server.address();
const usedPort =
address && typeof address === "object" ? address.port : port;
log.info(`Listening on ${host ?? ""}:${usedPort}`);
for (const accessibleHost of accessibleHosts) {
log.info(`- ${protocol}://${accessibleHost}:${port}`);
log.info(`- ${protocol}://${accessibleHost}:${usedPort}`);
}
resolve(server);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/miniflare/test/api.spec.ts
Expand Up @@ -169,7 +169,7 @@ test.serial("Miniflare: startServer: starts HTTP server", async (t) => {
const port = (server.address() as AddressInfo).port;
const res = await fetch(`http://localhost:${port}/`);
t.is(await res.text(), "body");
t.is(logs[0], "[mf:inf] Listening on :0");
t.regex(logs[0], /\[mf:inf\] Listening on :\d+/);
t.regex(logs[logs.length - 1], /^GET \/ 200 OK/);
});
test.serial("Miniflare: startScheduler: starts CRON scheduler", async (t) => {
Expand Down

0 comments on commit 9265fa4

Please sign in to comment.