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 })