UNPKG

studiocms

Version:

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

32 lines (29 loc) 883 B
import { SDKCore } from 'studiocms:sdk'; import { AllResponse, createEffectAPIRoutes, createJsonResponse, Effect, genLogger, OptionsResponse, } from '../../../effect.js'; export 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 = 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 }); }, } );