UNPKG

studiocms

Version:

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

37 lines (34 loc) 907 B
import logger from 'studiocms:logger'; 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/update-latest-version-cache/GET')(function* () { const sdk = yield* SDKCore; const latestVersion = yield* sdk.UPDATE.latestVersion(); return createJsonResponse({ success: true, latestVersion }); }), OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ['GET'] })), ALL: () => Effect.try(() => AllResponse()), }, { cors: { methods: ['GET', 'OPTIONS'] }, onError: (error) => { logger.error(`API Error: ${(error as Error).message}`); return createJsonResponse( { error: 'Something went wrong' }, { status: 500, } ); }, } );