-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07e8bd1
commit ca02ba9
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |