diff options
-rw-r--r-- | cli/bench/http/deno_flash_hono_router.js | 2 | ||||
-rw-r--r-- | cli/tests/unit/serve_test.ts | 59 | ||||
-rw-r--r-- | cli/tests/unit_node/async_hooks_test.ts | 8 | ||||
-rw-r--r-- | cli/tsc/dts/lib.deno.unstable.d.ts | 5 | ||||
-rw-r--r-- | ext/http/00_serve.js | 1 |
5 files changed, 37 insertions, 38 deletions
diff --git a/cli/bench/http/deno_flash_hono_router.js b/cli/bench/http/deno_flash_hono_router.js index ef78849b2..062c37cbf 100644 --- a/cli/bench/http/deno_flash_hono_router.js +++ b/cli/bench/http/deno_flash_hono_router.js @@ -7,4 +7,4 @@ const [hostname, port] = addr.split(":"); const app = new Hono(); app.get("/", (c) => c.text("Hello, World!")); -Deno.serve(app.fetch, { port: Number(port), hostname }); +Deno.serve({ port: Number(port), hostname }, app.fetch); diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts index 55b7c4590..2bdfbfe3c 100644 --- a/cli/tests/unit/serve_test.ts +++ b/cli/tests/unit/serve_test.ts @@ -248,7 +248,12 @@ Deno.test({ permissions: { net: true } }, async function httpServerOverload2() { const promise = deferred(); const listeningPromise = deferred(); - const server = Deno.serve(async (request) => { + const server = Deno.serve({ + port: 4501, + signal: ac.signal, + onListen: onListen(listeningPromise), + onError: createOnErrorCb(ac), + }, async (request) => { // FIXME(bartlomieju): // make sure that request can be inspected console.log(request); @@ -256,11 +261,6 @@ Deno.test({ permissions: { net: true } }, async function httpServerOverload2() { assertEquals(await request.text(), ""); promise.resolve(); return new Response("Hello World", { headers: { "foo": "bar" } }); - }, { - port: 4501, - signal: ac.signal, - onListen: onListen(listeningPromise), - onError: createOnErrorCb(ac), }); await listeningPromise; @@ -1015,12 +1015,15 @@ Deno.test( const promise = deferred(); const ac = new AbortController(); - const server = Deno.serve((request) => { - assert(request.body); + const server = Deno.serve( + { port: 2333, signal: ac.signal }, + (request) => { + assert(request.body); - promise.resolve(); - return new Response(request.body); - }, { port: 2333, signal: ac.signal }); + promise.resolve(); + return new Response(request.body); + }, + ); const ts = new TransformStream(); const writable = ts.writable.getWriter(); @@ -2484,10 +2487,7 @@ Deno.test( const ac = new AbortController(); const promise = deferred(); let count = 0; - const server = Deno.serve(() => { - count++; - return new Response(`hello world ${count}`); - }, { + const server = Deno.serve({ async onListen({ port }: { port: number }) { const res1 = await fetch(`http://localhost:${port}/`); assertEquals(await res1.text(), "hello world 1"); @@ -2499,6 +2499,9 @@ Deno.test( ac.abort(); }, signal: ac.signal, + }, () => { + count++; + return new Response(`hello world ${count}`); }); await promise; @@ -2552,7 +2555,16 @@ Deno.test( async function testIssue16567() { const ac = new AbortController(); const promise = deferred(); - const server = Deno.serve(() => + const server = Deno.serve({ + async onListen({ port }) { + const res1 = await fetch(`http://localhost:${port}/`); + assertEquals((await res1.text()).length, 40 * 50_000); + + promise.resolve(); + ac.abort(); + }, + signal: ac.signal, + }, () => new Response( new ReadableStream({ start(c) { @@ -2563,16 +2575,7 @@ Deno.test( c.close(); }, }), - ), { - async onListen({ port }) { - const res1 = await fetch(`http://localhost:${port}/`); - assertEquals((await res1.text()).length, 40 * 50_000); - - promise.resolve(); - ac.abort(); - }, - signal: ac.signal, - }); + )); await promise; await server; @@ -2716,8 +2719,8 @@ Deno.test( async function httpServeCurlH2C() { const ac = new AbortController(); const server = Deno.serve( - () => new Response("hello world!"), { signal: ac.signal }, + () => new Response("hello world!"), ); assertEquals( @@ -2747,12 +2750,12 @@ Deno.test( async function httpsServeCurlH2C() { const ac = new AbortController(); const server = Deno.serve( - () => new Response("hello world!"), { signal: ac.signal, cert: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.crt"), key: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.key"), }, + () => new Response("hello world!"), ); assertEquals( diff --git a/cli/tests/unit_node/async_hooks_test.ts b/cli/tests/unit_node/async_hooks_test.ts index 73d6a99bc..406244315 100644 --- a/cli/tests/unit_node/async_hooks_test.ts +++ b/cli/tests/unit_node/async_hooks_test.ts @@ -41,7 +41,10 @@ Deno.test(async function bar() { let differentScopeDone = false; const als = new AsyncLocalStorage(); const ac = new AbortController(); - const server = Deno.serve(() => { + const server = Deno.serve({ + signal: ac.signal, + port: 4000, + }, () => { const differentScope = als.run(123, () => AsyncResource.bind(() => { differentScopeDone = true; @@ -54,9 +57,6 @@ Deno.test(async function bar() { await new Promise((res) => setTimeout(res, 10)); return new Response(als.getStore() as string); // "Hello World" }); - }, { - signal: ac.signal, - port: 4000, }); const res = await fetch("http://localhost:4000"); diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index c11bfb09e..cf6cedf41 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -1361,10 +1361,7 @@ declare namespace Deno { * * @category HTTP Server */ - export function serve( - handler: ServeHandler, - options?: ServeOptions | ServeTlsOptions, - ): Promise<void>; + export function serve(handler: ServeHandler): Promise<void>; /** **UNSTABLE**: New API, yet to be vetted. * * Serves HTTP requests with the given handler. diff --git a/ext/http/00_serve.js b/ext/http/00_serve.js index 6e8f846df..1efa4cddb 100644 --- a/ext/http/00_serve.js +++ b/ext/http/00_serve.js @@ -425,7 +425,6 @@ async function serve(arg1, arg2) { let handler = undefined; if (typeof arg1 === "function") { handler = arg1; - options = arg2; } else if (typeof arg2 === "function") { handler = arg2; options = arg1; |