@sanity/form-toolkit
3.0.193.0.20
dist/create-handler-BzQC0x3G.js+
dist/create-handler-BzQC0x3G.jsNew file+43
Index: package/dist/create-handler-BzQC0x3G.js
===================================================================
--- package/dist/create-handler-BzQC0x3G.js
+++ package/dist/create-handler-BzQC0x3G.js
@@ -0,0 +1,43 @@
+import { defineEventHandler } from "h3";
+const detectFramework = () => process.env.NEXT_RUNTIME ? "nextjs" : process.env.NUXT_ENV ? "nuxt" : process.env.SVELTEKIT_ENV ? "sveltekit" : process.env.REMIX_ENV ? "remix" : process.env.ASTRO_ENV ? "astro" : "nextjs", createHandler = (handlerFunc) => {
+ let framework = detectFramework(), handlerLogic = async ({ res }) => {
+ try {
+ let data = await handlerFunc();
+ return res && (res.writeHead(200, { "Content-Type": "application/json" }), res.end(JSON.stringify(data))), data;
+ } catch (error) {
+ return error instanceof Error ? (res && (res.writeHead(500, { "Content-Type": "application/json" }), res.end(JSON.stringify({ error: error.message }))), { error: error.message }) : (res && (res.writeHead(500, { "Content-Type": "application/json" }), res.end(JSON.stringify({ error: "An unexpected error occurred" }))), { error: "An unexpected error occurred" });
+ }
+ };
+ if (framework === "nextjs") return async (req, res) => {
+ res.setHeader("Access-Control-Allow-Origin", "*"), res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"), res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization"), req.method === "OPTIONS" ? (res.writeHead(204), res.end()) : await handlerLogic({
+ req,
+ res
+ });
+ };
+ if (framework === "nuxt") return defineEventHandler(async (event) => {
+ let req = event.node.req, res = event.node.res;
+ return handlerLogic({
+ req,
+ res
+ });
+ });
+ if (framework === "sveltekit") return { GET: async ({ request }) => {
+ let result = await handlerLogic({ req: request });
+ return new Response(JSON.stringify(result), { headers: { "Content-Type": "application/json" } });
+ } };
+ if (framework === "remix") return { loader: async ({ request }) => {
+ let result = await handlerLogic({ req: request });
+ return new Response(JSON.stringify(result), { headers: { "Content-Type": "application/json" } });
+ } };
+ if (framework === "astro") return { get: async ({ request }) => {
+ let result = await handlerLogic({ req: request });
+ return {
+ body: JSON.stringify(result),
+ headers: { "Content-Type": "application/json" }
+ };
+ } };
+ throw Error(`Unsupported framework: ${framework}`);
+};
+export { createHandler as t };
+
+//# sourceMappingURL=create-handler-BzQC0x3G.js.map
\ No newline at end of file