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

fix: serve handler error with 0 arguments #23652

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/http/00_serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,9 @@ internals.serveHttpOnConnection = serveHttpOnConnection;

function registerDeclarativeServer(exports) {
if (ObjectHasOwn(exports, "fetch")) {
if (typeof exports.fetch !== "function" || exports.fetch.length !== 1) {
if (typeof exports.fetch !== "function") {
throw new TypeError(
"Invalid type for fetch: must be a function with a single parameter",
"Invalid type for fetch: must be a function with a single or no parameter",
);
}
return ({ servePort, serveHost }) => {
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/serve/no_args/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "serve --port 12345 main.ts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does deno serve find an open port? Maybe we should exclude it from the test? This port conflicts with another test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to pick to an open port here? deno serve doesn't find an open port.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fix it #23846

"output": "main.out",
"tempDir": true
}
1 change: 1 addition & 0 deletions tests/specs/serve/no_args/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deno serve: Listening on http://localhost:12345/
18 changes: 18 additions & 0 deletions tests/specs/serve/no_args/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(async () => {
for (let i = 0; i < 1000; i++) {
try {
const resp = await fetch("http://localhost:12345/");
Deno.exit(0);
} catch {
await new Promise((r) => setTimeout(r, 10));
}
}

Deno.exit(2);
})();

export default {
fetch() {
return new Response("Hello world!");
},
};