Skip to content

Commit

Permalink
add test for http2 node adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 22, 2024
1 parent f49f180 commit f22ea93
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions testbed/basic/ci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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",
Expand Down
23 changes: 23 additions & 0 deletions testbed/basic/entry-node-http2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @ts-check
import * as http2 from "node:http2";
import { createMiddleware } from "@hattip/adapter-node/http2";
import handler from "./index.js";
import { walk } from "@hattip/walk";
import { createStaticMiddleware } from "@hattip/static/node";

const root = new URL("./public", import.meta.url);
const files = walk(root);

/**
* @type {(request: http2.Http2ServerRequest, response: http2.Http2ServerResponse) => boolean}
*/
const staticMiddleware = createStaticMiddleware(root, files, { gzip: true });
const middleware = createMiddleware(handler);

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");
});

0 comments on commit f22ea93

Please sign in to comment.