diff --git a/testbed/basic/ci.test.ts b/testbed/basic/ci.test.ts index 5c2a5076..7c6a54a6 100644 --- a/testbed/basic/ci.test.ts +++ b/testbed/basic/ci.test.ts @@ -96,6 +96,11 @@ if (process.env.CI === "true") { command: `node entry-node-fast-fetch.js`, skipCryptoTest: nodeVersionMajor < 16, }, + { + name: "Node HTTP/2 with native fetch", + platform: "node", + command: "node --experimental-fetch entry-node-http2.js", + }, { name: "Deno", platform: "deno", diff --git a/testbed/basic/entry-node-http2.js b/testbed/basic/entry-node-http2.js index 17f5963d..c06d7b50 100644 --- a/testbed/basic/entry-node-http2.js +++ b/testbed/basic/entry-node-http2.js @@ -1,17 +1,23 @@ // @ts-check -import { createServer } from "node:http2"; -import connect from "connect"; -import { createMiddleware } from "@hattip/adapter-node/native-fetch"; +import * as http2 from "node:http2"; +import { createMiddleware } from "@hattip/adapter-node/http2"; import handler from "./index.js"; -import sirv from "sirv"; +import { walk } from "@hattip/walk"; +import { createStaticMiddleware } from "@hattip/static/node"; -const app = connect(); +const root = new URL("./public", import.meta.url); +const files = walk(root); -app.use(sirv("public")); -app.use(createMiddleware(handler)); +/** + * @type {(request: http2.Http2ServerRequest, response: http2.Http2ServerResponse) => boolean} + */ +const staticMiddleware = createStaticMiddleware(root, files, { gzip: true }); +const middleware = createMiddleware(handler); -createServer(); - -createServer(app).listen(3000, "127.0.0.1", () => { - console.log("Server listening on http://127.0.0.1:3000"); -}); +http2 + .createServer((req, res) => { + return staticMiddleware(req, res) || middleware(req, res); + }) + .listen(3000, "127.0.0.1", () => { + console.log("Server listening on http://127.0.0.1:3000"); + });