UNPKG

autumn-js

Version:
44 lines (41 loc) 988 B
import { createCoreHandler } from "./chunk-RHDPT37C.mjs"; // src/backend/adapters/fetch.ts function autumnHandler(options) { const core = createCoreHandler({ identify: (raw) => options.identify(raw), secretKey: options.secretKey, autumnURL: options.autumnURL, pathPrefix: options.pathPrefix }); const handle = async (request) => { const url = new URL(request.url); console.log(url); let body = null; if (request.method !== "GET") { try { body = await request.json(); } catch { body = null; } } const result = await core({ method: request.method, path: url.pathname, body, raw: request }); if (result.status === 204) { return new Response(null, { status: 204 }); } return new Response(JSON.stringify(result.body), { status: result.status, headers: { "Content-Type": "application/json" } }); }; return handle; } export { autumnHandler };