Files
Noel Sabia 233fdbf66c feat: live SSE stage, phone view and presenter control
- proxy Go /api/stream through Nitro; drive /stage, /live, /plan and /forecast from scenario events
- fall back to 5 s polling after SSE failures or heartbeat silence; show Live/Polling/Offline
- authenticate /control and POST /api/scenario in Nitro with server-side control credentials
- add big-screen stage with local QR and a no-login phone recommendation view
- add SSE unit tests and a live smoke test; refresh README/Makefile
2026-11-14 06:59:07 +01:00

28 lines
948 B
TypeScript

import { SCENARIOS } from '../../shared/types'
import type { Scenario, ScenarioDefinition, ScenarioState } from '../../shared/types'
import { apiRequest, isMockMode } from '../utils/api'
import { setMockScenario } from '../utils/mock-scenario'
export default defineEventHandler(async (event) => {
const body = await readBody<ScenarioDefinition>(event)
const scenario = body?.scenario
if (!scenario || !SCENARIOS.includes(scenario as Scenario)) {
throw createError({
statusCode: 400,
statusMessage: 'Invalid scenario. Expected base | sunny-saturday-market | rainy-saturday | weekday-event.',
})
}
if (isMockMode()) {
return setMockScenario(body)
}
// Control credentials are attached in the server process, never in the
// browser. Go returns 503 until CONTROL_USER/CONTROL_PASS are configured.
return apiRequest<ScenarioState>('/api/scenario', {
method: 'POST',
body,
control: true,
})
})