Skip to content

Commit f22ea93

Browse files
committed
add test for http2 node adapter
1 parent f49f180 commit f22ea93

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

testbed/basic/ci.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ if (process.env.CI === "true") {
7777
command: `node entry-node-fast-fetch.js`,
7878
skipCryptoTest: nodeVersionMajor < 16,
7979
},
80+
{
81+
name: "Node HTTP/2 with native fetch",
82+
platform: "node",
83+
command: "node --experimental-fetch entry-node-http2.js",
84+
},
8085
{
8186
name: "Deno",
8287
platform: "deno",

testbed/basic/entry-node-http2.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @ts-check
2+
import * as http2 from "node:http2";
3+
import { createMiddleware } from "@hattip/adapter-node/http2";
4+
import handler from "./index.js";
5+
import { walk } from "@hattip/walk";
6+
import { createStaticMiddleware } from "@hattip/static/node";
7+
8+
const root = new URL("./public", import.meta.url);
9+
const files = walk(root);
10+
11+
/**
12+
* @type {(request: http2.Http2ServerRequest, response: http2.Http2ServerResponse) => boolean}
13+
*/
14+
const staticMiddleware = createStaticMiddleware(root, files, { gzip: true });
15+
const middleware = createMiddleware(handler);
16+
17+
http2
18+
.createServer((req, res) => {
19+
return staticMiddleware(req, res) || middleware(req, res);
20+
})
21+
.listen(3000, "127.0.0.1", () => {
22+
console.log("Server listening on http://127.0.0.1:3000");
23+
});

0 commit comments

Comments
 (0)