1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

feat(serve): Support second parameter in deno serve (#25606)

Closes #24099
This commit is contained in:
Nathan Whitaker 2024-09-12 16:32:28 -07:00 committed by GitHub
parent 018329a4d3
commit 7477c2d706
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 36 additions and 8 deletions

View file

@ -5090,9 +5090,7 @@ declare namespace Deno {
*
* @category HTTP Server
*/
fetch: (
request: Request,
) => Response | Promise<Response>;
fetch: ServeHandler;
}
/** Options which can be set when calling {@linkcode Deno.serve}.

View file

@ -880,8 +880,8 @@ function registerDeclarativeServer(exports) {
);
}
},
handler: (req) => {
return exports.fetch(req);
handler: (req, connInfo) => {
return exports.fetch(req, connInfo);
},
});
};

View file

@ -3,12 +3,12 @@
"tests": {
"basic_win": {
"if": "windows",
"args": "serve --host 0.0.0.0 --port 12345 main.ts",
"args": "serve --check --host 0.0.0.0 --port 12345 main.ts",
"output": "main.out"
},
"basic_not_win": {
"if": "unix",
"args": "serve --host 0.0.0.0 --port 12345 main.ts",
"args": "serve --check --host 0.0.0.0 --port 12345 main.ts",
"output": "main_not_win.out"
}
}

View file

@ -1 +1,2 @@
Check [WILDCARD]
deno serve: Listening on http://localhost:12345/

View file

@ -15,4 +15,4 @@ export default {
fetch(req) {
return new Response("Hello world!");
},
};
} satisfies Deno.ServeDefaultExport;

View file

@ -1 +1,2 @@
Check [WILDCARD]
deno serve: Listening on http://0.0.0.0:12345/

View file

@ -0,0 +1,6 @@
{
"args": "serve --check --port 12468 main.ts",
"output": "main.out",
"tempDir": true,
"exitCode": 0
}

View file

@ -0,0 +1,3 @@
Check [WILDCARD]main.ts
deno serve: Listening on http://[WILDCARD]
ServeHandlerInfo {}

View file

@ -0,0 +1,19 @@
(async () => {
for (let i = 0; i < 1000; i++) {
try {
const resp = await fetch("http://localhost:12468/");
Deno.exit(0);
} catch {
await new Promise((r) => setTimeout(r, 10));
}
}
Deno.exit(2);
})();
export default {
fetch(request, connInfo) {
console.log(connInfo);
return new Response("Hello world!");
},
} satisfies Deno.ServeDefaultExport;