UNPKG

studiocms

Version:

Astro Native CMS for AstroDB. Built from the ground up by the Astro community.

44 lines (43 loc) 1.54 kB
import { SDKCore } from "studiocms:sdk"; import { AllResponse, createEffectAPIRoutes, createJsonResponse, Effect, genLogger, OptionsResponse } from "../../../effect.js"; const { ALL, OPTIONS, GET } = createEffectAPIRoutes( { GET: () => genLogger("routes/sdk/list-pages/GET")(function* () { const sdk = yield* SDKCore; const pages = yield* sdk.GET.pages(); const lastUpdated = (/* @__PURE__ */ new Date()).toISOString(); return createJsonResponse({ lastUpdated, pages }); }), OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ["GET"] })), ALL: () => Effect.try(() => AllResponse()) }, { cors: { methods: ["GET", "OPTIONS"] }, onError: (error) => { const status = typeof error === "object" && error !== null && // biome-ignore lint/suspicious/noExplicitAny: Allows for better error handling "status" in error && // biome-ignore lint/suspicious/noExplicitAny: Allows for better error handling typeof error.status === "number" ? ( // biome-ignore lint/suspicious/noExplicitAny: Allows for better error handling error.status ) : 500; const message = ( // biome-ignore lint/suspicious/noExplicitAny: Allows for better error handling status >= 500 ? "Something went wrong" : error?.message ?? "Request failed" ); console.error("routes/sdk/list-pages error", { status, message }); return createJsonResponse({ error: message }, { status }); } } ); export { ALL, GET, OPTIONS };