1import { ENGINE_CATALOG } from './catalog'23function json(value: unknown, init: ResponseInit = {}): Response {4 const headers = new Headers(init.headers)5 headers.set('Content-Type', 'application/json; charset=utf-8')6 headers.set('Cache-Control', 'no-store')7 headers.set('Access-Control-Allow-Origin', '*')8 return Response.json(value, { ...init, headers })9}1011function catalogResponse(): Response {12 return json({ format: 'svg', engines: ENGINE_CATALOG }, {13 headers: { 'Cache-Control': 'public, max-age=300' },14 })15}1617export default {18 async fetch(request: Request): Promise<Response> {19 const url = new URL(request.url)20 if (request.method === 'OPTIONS') {21 return new Response(null, {22 status: 204,23 headers: {24 'Access-Control-Allow-Headers': 'Accept, Content-Type',25 'Access-Control-Allow-Methods': 'GET, OPTIONS',26 'Access-Control-Allow-Origin': '*',27 'Access-Control-Max-Age': '86400',28 },29 })30 }31 if (request.method === 'GET' && url.pathname === '/render/v1/health') return json({ ok: true })32 if (request.method === 'GET' && url.pathname === '/render/v1/catalog') return catalogResponse()33 return json({ error: { code: 'not_found', message: 'Route not found.' } }, { status: 404 })34 },35} satisfies ExportedHandler<Env>