import { apiBaseUrl, isMockMode } from '../utils/api' /** * Same-origin SSE proxy. The browser never talks to Go directly, so the * Cloudflare/K8s CORS surface stays closed and the stream can be cached or * authenticated at one edge only. * * h3's proxyRequest pipes response chunks as they arrive (it does not await * the full body), which preserves the 15 s heartbeat and `retry: 3000`. */ export default defineEventHandler(async (event) => { if (isMockMode() || process.env.NUXT_DISABLE_SSE === '1') { // Failure drill: make the client prove the 5 s polling fallback. Mock mode // has no upstream stream either, so both paths fail fast and visibly. throw createError({ statusCode: 503, statusMessage: 'SSE is disabled; the scenario polling fallback is active.', }) } return proxyRequest(event, `${apiBaseUrl()}/api/stream`, { headers: { accept: 'text/event-stream' }, }) })