mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 04:51:22 +00:00
feat(serve): Support second parameter in deno serve (#25606)
Closes #24099
This commit is contained in:
parent
018329a4d3
commit
7477c2d706
4
cli/tsc/dts/lib.deno.ns.d.ts
vendored
4
cli/tsc/dts/lib.deno.ns.d.ts
vendored
@ -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}.
|
||||
|
@ -880,8 +880,8 @@ function registerDeclarativeServer(exports) {
|
||||
);
|
||||
}
|
||||
},
|
||||
handler: (req) => {
|
||||
return exports.fetch(req);
|
||||
handler: (req, connInfo) => {
|
||||
return exports.fetch(req, connInfo);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -1 +1,2 @@
|
||||
Check [WILDCARD]
|
||||
deno serve: Listening on http://localhost:12345/
|
||||
|
@ -15,4 +15,4 @@ export default {
|
||||
fetch(req) {
|
||||
return new Response("Hello world!");
|
||||
},
|
||||
};
|
||||
} satisfies Deno.ServeDefaultExport;
|
||||
|
@ -1 +1,2 @@
|
||||
Check [WILDCARD]
|
||||
deno serve: Listening on http://0.0.0.0:12345/
|
||||
|
6
tests/specs/serve/conn_info/__test__.jsonc
Normal file
6
tests/specs/serve/conn_info/__test__.jsonc
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"args": "serve --check --port 12468 main.ts",
|
||||
"output": "main.out",
|
||||
"tempDir": true,
|
||||
"exitCode": 0
|
||||
}
|
3
tests/specs/serve/conn_info/main.out
Normal file
3
tests/specs/serve/conn_info/main.out
Normal file
@ -0,0 +1,3 @@
|
||||
Check [WILDCARD]main.ts
|
||||
deno serve: Listening on http://[WILDCARD]
|
||||
ServeHandlerInfo {}
|
19
tests/specs/serve/conn_info/main.ts
Normal file
19
tests/specs/serve/conn_info/main.ts
Normal 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;
|
Loading…
Reference in New Issue
Block a user