1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix(ext/flash): fix default onListen callback (#15533)

This commit is contained in:
Yoshiya Hinosawa 2022-08-22 17:01:43 +09:00 committed by GitHub
parent 301f6c46ba
commit 57d48134d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View file

@ -101,6 +101,40 @@ Deno.test({ permissions: { net: true } }, async function httpServerPort0() {
await server;
});
Deno.test(
{ permissions: { net: true } },
async function httpServerDefaultOnListenCallback() {
const ac = new AbortController();
const consoleLog = console.log;
console.log = (msg) => {
try {
const match = msg.match(/Listening on http:\/\/localhost:(\d+)\//);
assert(!!match);
const port = +match[1];
assert(port > 0 && port < 65536);
} finally {
ac.abort();
}
};
try {
const server = Deno.serve({
fetch() {
return new Response("Hello World");
},
hostname: "0.0.0.0",
port: 0,
signal: ac.signal,
});
await server;
} finally {
console.log = consoleLog;
}
},
);
// https://github.com/denoland/deno/issues/15107
Deno.test(
{ permissions: { net: true } },

View file

@ -205,11 +205,9 @@
return new Response("Internal Server Error", { status: 500 });
};
delete opts.onError;
const onListen = opts.onListen ?? function () {
const onListen = opts.onListen ?? function ({ port }) {
console.log(
`Listening on http://${
hostnameForDisplay(opts.hostname)
}:${opts.port}/`,
`Listening on http://${hostnameForDisplay(opts.hostname)}:${port}/`,
);
};
delete opts.onListen;