From 84b001e651f13a8a7bc3febb6a23f6997e6d8dd8 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Wed, 22 Oct 2025 14:54:17 -0700 Subject: [PATCH] work with routes() helper --- src/helpers.tsx | 4 ++-- src/webapp/worker.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/helpers.tsx b/src/helpers.tsx index 4a441e5..b4bda4c 100644 --- a/src/helpers.tsx +++ b/src/helpers.tsx @@ -48,8 +48,8 @@ export function routes(def: Record): Hono { for (const key in def) { const parts = key.split(" ") // GET /path - const method = parts[0] || "GET" - const path = parts[1] || "/" + const method = (!parts[0] || parts[0].startsWith("/")) ? "GET" : parts[0] + const path = (parts[0]?.startsWith("/") ? parts[0] : parts[1]) || "/" //@ts-ignore app.on(method, path, async c => toResponse(await def[key](c))) diff --git a/src/webapp/worker.ts b/src/webapp/worker.ts index 72ea8e5..d91c7f0 100644 --- a/src/webapp/worker.ts +++ b/src/webapp/worker.ts @@ -22,13 +22,18 @@ try { } const handler = mod.default -if (typeof handler !== "function") { +let app: Hono + +if (typeof handler === "function") { + app = new Hono + app.all("*", async c => toResponse(await handler(c))) +} else if (handler && typeof handler === "object" && handler.routes && handler.router) { + app = handler +} else { webappLog(appName, `no default export`) process.exit(1) } -const app = new Hono() -app.all("*", async c => toResponse(await handler(c))) const port = Number(process.env.PORT || 4000) Bun.serve({ port, fetch: app.fetch })