Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix --port=0 logging #382

Merged
merged 1 commit into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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