// GET /api/__seo__/resolve?url=: the resolve answer through // the layer's server (and its cache), for client-side navigation on a site // whose proxy does not route /_seo/api/v1 to the backend. The browser uses // it when public.seo.apiBase (NUXT_PUBLIC_SEO_API_BASE) is "/api/__seo__"; // the default stays the backend's same-origin /_seo/api/v1. // // 404 when the layer is off; 422 for a url that is not a path; 502 when the // backend gives no usable answer. Never route-cached ('/api/__seo__/**' // cache false) and never indexed. import { seoServerConfig } from '../../lib/config.ts' import { resolveCached } from '../../lib/resolve.ts' export default defineEventHandler(async (event) => { setResponseHeaders(event, { 'cache-control': 'no-store', 'x-robots-tag': 'noindex' }) if (!seoServerConfig(useRuntimeConfig(event)).enabled) throw createError({ statusCode: 404, statusMessage: 'Not Found' }) const url = getQuery(event).url if (typeof url !== 'string' || !url.startsWith('/') || url.startsWith('//') || url.length > 2048) { throw createError({ statusCode: 422, statusMessage: 'Bad url' }) } const answer = await resolveCached(event, url) if (!answer) throw createError({ statusCode: 502, statusMessage: 'No SEO answer' }) return answer })