UNPKG

studiocms

Version:

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

34 lines (33 loc) 962 B
import { SDKCore } from "studiocms:sdk"; import { AllResponse, createEffectAPIRoutes, createJsonResponse, Effect, genLogger, OptionsResponse } from "../../../../effect.js"; const { ALL, OPTIONS, GET } = createEffectAPIRoutes( { GET: () => genLogger("routes/sdk/fallback-list-pages.json/GET")(function* () { const sdk = yield* SDKCore; const pages = yield* sdk.GET.pages(); const lastUpdated = (/* @__PURE__ */ new Date()).toISOString(); return createJsonResponse({ lastUpdated, pages: pages.map((pageItem) => pageItem.data) }); }), OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ["GET"] })), ALL: () => Effect.try(() => AllResponse()) }, { cors: { methods: ["GET", "OPTIONS"] }, onError: (error) => { console.error("API Error:", error); return createJsonResponse({ error: "Something went wrong" }, { status: 500 }); } } ); export { ALL, GET, OPTIONS };