diff options
author | Luca Casonato <hello@lcas.dev> | 2022-08-24 00:08:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-24 00:08:56 +0200 |
commit | 4ef08a58dfbcf893f25fd59917aa946f455e85f2 (patch) | |
tree | 7b1e07869fd23f1ce65029ab3725b9ef054f7576 /cli/bench | |
parent | f0993f413b86997674ea4bc6812af7d2c529ec96 (diff) |
feat: update `Deno.serve` function signature (#15563)
This commit changes the `Deno.serve` function signature to be more
versatile and easier to use. It is now a drop in replacement for
std/http's `serve`.
The input validation has also been reworked.
Diffstat (limited to 'cli/bench')
-rw-r--r-- | cli/bench/http/deno_flash_hono_router.js | 2 | ||||
-rw-r--r-- | cli/bench/http/deno_flash_send_file.js | 4 | ||||
-rw-r--r-- | cli/bench/http/deno_http_flash.js | 8 | ||||
-rw-r--r-- | cli/bench/http/deno_reactdom_ssr_flash.jsx | 12 | ||||
-rw-r--r-- | cli/bench/testdata/deno_upgrade_http.js | 8 |
5 files changed, 10 insertions, 24 deletions
diff --git a/cli/bench/http/deno_flash_hono_router.js b/cli/bench/http/deno_flash_hono_router.js index 4c3336c63..af6adc9ba 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({ fetch: app.fetch, port: Number(port), hostname }); +Deno.serve(app.fetch, { port: Number(port), hostname }); diff --git a/cli/bench/http/deno_flash_send_file.js b/cli/bench/http/deno_flash_send_file.js index 81e8c4991..db2ad7a82 100644 --- a/cli/bench/http/deno_flash_send_file.js +++ b/cli/bench/http/deno_flash_send_file.js @@ -6,9 +6,9 @@ const { serve } = Deno; const path = new URL("../testdata/128k.bin", import.meta.url).pathname; -function fetch() { +function handler() { const file = Deno.openSync(path); return new Response(file.readable); } -serve({ fetch, hostname, port: Number(port) }); +serve(handler, { hostname, port: Number(port) }); diff --git a/cli/bench/http/deno_http_flash.js b/cli/bench/http/deno_http_flash.js index 3823bb9cd..7c486f422 100644 --- a/cli/bench/http/deno_http_flash.js +++ b/cli/bench/http/deno_http_flash.js @@ -4,12 +4,8 @@ const addr = Deno.args[0] || "127.0.0.1:4500"; const [hostname, port] = addr.split(":"); const { serve } = Deno; -function fetch() { +function handler() { return new Response("Hello World"); } -serve({ - fetch, - hostname, - port, -}); +serve(handler, { hostname, port }); diff --git a/cli/bench/http/deno_reactdom_ssr_flash.jsx b/cli/bench/http/deno_reactdom_ssr_flash.jsx index 0d749c634..42c955624 100644 --- a/cli/bench/http/deno_reactdom_ssr_flash.jsx +++ b/cli/bench/http/deno_reactdom_ssr_flash.jsx @@ -18,12 +18,6 @@ const headers = { }, }; -serve( - { - fetch: async () => { - return new Response(await renderToReadableStream(<App />), headers); - }, - hostname, - port, - }, -); +serve({ hostname, port }, async () => { + return new Response(await renderToReadableStream(<App />), headers); +}); diff --git a/cli/bench/testdata/deno_upgrade_http.js b/cli/bench/testdata/deno_upgrade_http.js index e3252ffd1..7274459c9 100644 --- a/cli/bench/testdata/deno_upgrade_http.js +++ b/cli/bench/testdata/deno_upgrade_http.js @@ -1,14 +1,10 @@ const { serve, upgradeHttp } = Deno; const u8 = Deno.core.encode("HTTP/1.1 101 Switching Protocols\r\n\r\n"); -async function fetch(req) { +async function handler(req) { const [conn, _firstPacket] = upgradeHttp(req); await conn.write(u8); await conn.close(); } -serve({ - fetch, - hostname: "127.0.0.1", - port: 9000, -}); +serve(handler, { hostname: "127.0.0.1", port: 9000 }); |