0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-10 06:07:03 -04:00

registerDeclarativeServer change

This commit is contained in:
ricfrst 2024-10-28 11:33:54 -04:00
parent 285635daa6
commit 6e0872c1f6
2 changed files with 7 additions and 2 deletions

View file

@ -862,7 +862,7 @@ internals.upgradeHttpRaw = upgradeHttpRaw;
internals.serveHttpOnListener = serveHttpOnListener; internals.serveHttpOnListener = serveHttpOnListener;
internals.serveHttpOnConnection = serveHttpOnConnection; internals.serveHttpOnConnection = serveHttpOnConnection;
function registerDeclarativeServer(exports) { export function registerDeclarativeServer(exports) {
if (ObjectHasOwn(exports, "fetch")) { if (ObjectHasOwn(exports, "fetch")) {
if (typeof exports.fetch !== "function") { if (typeof exports.fetch !== "function") {
throw new TypeError( throw new TypeError(
@ -882,7 +882,7 @@ function registerDeclarativeServer(exports) {
: ""; : "";
const host = formatHostName(hostname); const host = formatHostName(hostname);
// deno-lint-ignore no-console // Log server information
console.error( console.error(
`%cdeno serve%c: Listening on %chttp://${host}:${port}/%c${nThreads}`, `%cdeno serve%c: Listening on %chttp://${host}:${port}/%c${nThreads}`,
"color: green", "color: green",
@ -891,6 +891,11 @@ function registerDeclarativeServer(exports) {
"color: inherit", "color: inherit",
); );
} }
// Check if `onListen` is provided by `exports` and call it if present
if (typeof exports.onListen === "function") {
exports.onListen({ port, hostname });
}
}, },
handler: (req, connInfo) => { handler: (req, connInfo) => {
return exports.fetch(req, connInfo); return exports.fetch(req, connInfo);