UNPKG

@withstudiocms/effect

Version:

Effect-TS Utilities for Astro

68 lines (67 loc) 2.09 kB
const OptionsResponse = (opts) => new Response(null, { status: 204, statusText: "No Content", headers: { ...opts.headers, Allow: `OPTIONS, ${opts.allowedMethods.join(", ")}`, "Access-Control-Allow-Origin": opts.allowedOrigins?.join(", ") || "*", Date: (/* @__PURE__ */ new Date()).toUTCString() } }); const AllResponse = (opts) => new Response(null, { status: 405, statusText: "Method Not Allowed", headers: { ...opts?.headers, "Access-Control-Allow-Origin": opts?.allowedOrigins?.join(", ") || "*", Date: (/* @__PURE__ */ new Date()).toUTCString() } }); const createJsonResponse = (data, opts = {}) => new Response(JSON.stringify(data), { status: opts.status || 200, statusText: opts.statusText || "OK", headers: { "Content-Type": "application/json", ...opts?.headers, "Access-Control-Allow-Origin": opts?.allowedOrigins?.join(", ") || "*", Date: (/* @__PURE__ */ new Date()).toUTCString() } }); const createTextResponse = (data, opts = {}) => new Response(data, { status: opts.status || 200, statusText: opts.statusText || "OK", headers: { "Content-Type": "text/plain", ...opts?.headers, "Access-Control-Allow-Origin": opts?.allowedOrigins?.join(", ") || "*", Date: (/* @__PURE__ */ new Date()).toUTCString() } }); const createHtmlResponse = (data, opts = {}) => new Response(data, { status: opts.status || 200, statusText: opts.statusText || "OK", headers: { "Content-Type": "text/html", ...opts?.headers, "Access-Control-Allow-Origin": opts?.allowedOrigins?.join(", ") || "*", Date: (/* @__PURE__ */ new Date()).toUTCString() } }); const createRedirectResponse = (url, opts = {}) => new Response(null, { status: 302, statusText: "Found", headers: { Location: url, ...opts?.headers, "Access-Control-Allow-Origin": opts?.allowedOrigins?.join(", ") || "*", Date: (/* @__PURE__ */ new Date()).toUTCString() } }); export { AllResponse, OptionsResponse, createHtmlResponse, createJsonResponse, createRedirectResponse, createTextResponse };