UNPKG

autumn-js

Version:
42 lines (39 loc) 931 B
import { createCoreHandler } from "./chunk-RHDPT37C.mjs"; // src/backend/adapters/hono.ts function autumnHandler(options) { const core = createCoreHandler({ identify: (raw) => options.identify(raw), secretKey: options.secretKey, autumnURL: options.autumnURL, pathPrefix: options.pathPrefix }); return async (c, next) => { const url = new URL(c.req.url); let body = null; if (["POST", "PUT", "PATCH"].includes(c.req.method)) { try { body = await c.req.json(); } catch { body = null; } } const result = await core({ method: c.req.method, path: url.pathname, body, raw: c }); if (result.status === 404 && result.body?.code === "not_found") { return next(); } if (result.status === 204) { return c.body(null, 204); } return c.json(result.body, result.status); }; } export { autumnHandler };