Skip to content

Commit 0979663

Browse files
committed
feat: add hono backend
1 parent 73d8321 commit 0979663

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ on:
99
jobs:
1010
setup-and-test:
1111
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
server: [itty-router, hono]
15+
include:
16+
- server: itty-router
17+
build_cmd: npm run build
18+
- server: hono
19+
build_cmd: npm run build:hono
1220

21+
name: test (${{ matrix.server }})
1322
steps:
1423
- name: Checkout repository
1524
uses: actions/checkout@v4
@@ -23,9 +32,22 @@ jobs:
2332
curl https://wasmtime.dev/install.sh -sSf | bash
2433
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
2534
- name: Build the project
26-
run: npm ci && npm run build
35+
run: npm ci && ${{ matrix.build_cmd }}
2736
- name: Run tests
2837
run: npm test
38+
39+
lint:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
- name: Set up Node.js
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: "23"
48+
cache: "npm"
49+
- name: Install dependencies
50+
run: npm ci
2951
- name: Run format checks
3052
run: npm run fmt:check
3153
- name: Run linter

package-lock.json

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"scripts": {
1414
"bundle": "rolldown -c",
1515
"build": "npm run bundle && componentize-js --wit wit -o dist/$npm_package_name.wasm dist/bundle.js",
16+
"build:hono": "npm run bundle -- --input src/server-hono.js && componentize-js --wit wit -o dist/$npm_package_name.wasm dist/bundle.js",
1617
"serve": "npm run build && wasmtime serve -S common dist/$npm_package_name.wasm",
18+
"serve:hono": "npm run build:hono && wasmtime serve -S common dist/$npm_package_name.wasm",
1719
"fetch-wit": "wkg wit fetch",
1820
"update-wit": "wkg wit update",
1921
"fmt": "oxfmt",
@@ -23,6 +25,7 @@
2325
"test": "vitest --run"
2426
},
2527
"dependencies": {
28+
"hono": "^4.12.12",
2629
"itty-router": "^5.0.23"
2730
},
2831
"devDependencies": {

src/server-hono.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Hono } from "hono";
2+
3+
import { sleep } from "./endpoints/sleep.js";
4+
import { upload } from "./endpoints/upload.js";
5+
import { echo, echoHeaders } from "./endpoints/echo.js";
6+
7+
const app = new Hono();
8+
9+
app.get("/", (c) => c.text("Hello, World!"));
10+
app.get("/echo-headers", (c) => echoHeaders(c.req.raw));
11+
app.get("/sleep/:ms", async (c) => await sleep(c.req.param("ms")));
12+
app.post("/echo", (c) => echo(c.req.raw));
13+
app.post("/upload", (c) => upload(c.req.raw));
14+
15+
addEventListener("fetch", (event) => {
16+
event.respondWith(app.fetch(event.request));
17+
});

0 commit comments

Comments
 (0)