- Replace mock Nitro routes with server-side proxies to the Go API - /plan reads Go /api/staffing; local assumption edits are a labeled preview - /simulate reads base and scenario staffing from Go instead of local multipliers - Route train upload and scenario POST through Nitro with server-only credentials - Keep NUXT_PUBLIC_USE_MOCK=1 as an explicit dev fallback only - Match Go's global-peak flat schedule and add a captured Go parity fixture - Run the web runtime as numeric UID/GID 10001:10001 - Add make check, Gitea CI workflow and a proxy smoke script
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { applyScenario } from '../../shared/staffing'
|
|
import { HORIZONS, SCENARIOS } from '../../shared/types'
|
|
import type { ForecastResponse, Horizon, Scenario } from '../../shared/types'
|
|
import { apiRequest, enumParam, isMockMode, sensorParam } from '../utils/api'
|
|
import { getMockForecast } from '../utils/mock-data'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const query = getQuery(event)
|
|
const sensor = sensorParam(query.sensor)
|
|
const horizon = enumParam<Horizon>(query.horizon, HORIZONS, 'horizon', '7d')
|
|
const scenario = enumParam<Scenario>(query.scenario, SCENARIOS, 'scenario', 'base')
|
|
|
|
if (isMockMode()) {
|
|
const forecast = getMockForecast(sensor)
|
|
if (!forecast) {
|
|
throw createError({ statusCode: 404, statusMessage: `Unknown sensor: ${sensor}` })
|
|
}
|
|
const points = applyScenario(forecast.points, scenario)
|
|
const limit = horizon === '15m' ? 1 : horizon === '1h' ? 4 : horizon === '48h' ? 48 : points.length
|
|
return {
|
|
...forecast,
|
|
horizon,
|
|
scenario,
|
|
points: points.slice(0, limit),
|
|
cached: false,
|
|
}
|
|
}
|
|
|
|
return apiRequest<ForecastResponse>('/api/forecast', {
|
|
query: { sensor, horizon, scenario },
|
|
})
|
|
})
|