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

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

Merged
merged 3 commits into from
Sep 12, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
4 changes: 2 additions & 2 deletions ext/http/00_serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,8 @@ function registerDeclarativeServer(exports) {
);
}
},
handler: (req) => {
return exports.fetch(req);
handler: (req, connInfo) => {
return exports.fetch(req, connInfo);
},
});
};
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/serve/basic/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/specs/serve/basic/main.out
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Check [WILDCARD]
deno serve: Listening on http://localhost:12345/
2 changes: 1 addition & 1 deletion tests/specs/serve/basic/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export default {
fetch(req) {
return new Response("Hello world!");
},
};
} satisfies Deno.ServeDefaultExport;
1 change: 1 addition & 0 deletions tests/specs/serve/basic/main_not_win.out
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Check [WILDCARD]
deno serve: Listening on http://0.0.0.0:12345/
6 changes: 6 additions & 0 deletions tests/specs/serve/conn_info/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"args": "serve --check --port 12468 main.ts",
"output": "main.out",
"tempDir": true,
"exitCode": 0
}
3 changes: 3 additions & 0 deletions tests/specs/serve/conn_info/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Check [WILDCARD]main.ts
deno serve: Listening on http://[WILDCARD]
ServeHandlerInfo {}
19 changes: 19 additions & 0 deletions tests/specs/serve/conn_info/main.ts
Original file line number Diff line number Diff line change
@@ -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;