- Lead with purpose and exact local/CI commands. - Remove local absolute paths, stale auth notes and unverified claims. - Keep comments to the reason or invariant they protect.
21 lines
757 B
TypeScript
21 lines
757 B
TypeScript
import { apiBaseUrl, isMockMode } from '../utils/api'
|
|
|
|
/**
|
|
* Same-origin SSE proxy: the browser talks only to Nitro, so CORS stays closed.
|
|
* proxyRequest forwards chunks as they arrive, preserving heartbeats and retry hints.
|
|
*/
|
|
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' },
|
|
})
|
|
})
|