UNPKG

beckn-typescript

Version:

Beckn Protocol Client & Server Tools for Typescript

37 lines (36 loc) 1.04 kB
// server/next.ts var createNextMiddleware = (tools) => { const POST = async (req, { params }) => { try { if (req.method !== "POST") { return Response.json("Only POST Method Allowed", { status: 405 }); } const { path } = await params; if (!path || typeof path !== "string" || !(path in tools)) { return Response.json("Path or Tool Not Found", { status: 404 }); } const tool = tools[path]; const body = await req.json(); const response = await tool(req, body); return Response.json(response); } catch (error) { console.error("Error in API:", error); return Response.json("Unexpected error occurred in API", { status: 500 }); } }; return { POST }; }; var transactionServer = (tools) => createNextMiddleware(tools); var metaServer = (tools) => createNextMiddleware(tools); var registryServer = (tools) => createNextMiddleware(tools); export { transactionServer, registryServer, metaServer };