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 Dec 7, 2024
1 parent 9ad9402 commit cee461b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions testbed/basic/ci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 18 additions & 12 deletions testbed/basic/entry-node-http2.js
Original file line number Diff line number Diff line change
@@ -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");
});

0 comments on commit cee461b

Please sign in to comment.