UNPKG

autumn-js

Version:
45 lines (42 loc) 990 B
import { createCoreHandler } from "./chunk-RHDPT37C.mjs"; // src/backend/adapters/next.ts import { NextResponse } from "next/server"; 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); 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 NextResponse(null, { status: 204 }); } return NextResponse.json(result.body, { status: result.status }); }; return { GET: handle, POST: handle, DELETE: handle }; } export { autumnHandler };