feat: wire Nitro API to Go, real staffing plan and train proxy

- 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
This commit is contained in:
Noel Sabia committed 2026-11-14 06:13:00 +01:00
1 parent e8d141ca43
commit b33e6ff001
33 files changed
+1147 -317

No files matched your search

+23 -25
View File
@@ -1,34 +1,32 @@
import { applyScenario } from '../../shared/staffing'
import { HORIZONS, SCENARIOS } from '../../shared/types'
import type { Horizon, Scenario } 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((event) => {
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const sensor = String(query.sensor ?? 'hn-stadtgalerie-01')
const horizon = String(query.horizon ?? '7d') as Horizon
const scenario = String(query.scenario ?? 'base') as Scenario
const forecast = getMockForecast(sensor)
const sensor = sensorParam(query.sensor)
const horizon = enumParam<Horizon>(query.horizon, HORIZONS, 'horizon', '7d')
const scenario = enumParam<Scenario>(query.scenario, SCENARIOS, 'scenario', 'base')
if (!forecast) {
throw createError({ statusCode: 404, statusMessage: `Unknown sensor: ${sensor}` })
}
if (!HORIZONS.includes(horizon)) {
throw createError({ statusCode: 400, statusMessage: `Invalid horizon: ${horizon}` })
}
if (!SCENARIOS.includes(scenario)) {
throw createError({ statusCode: 400, statusMessage: `Invalid scenario: ${scenario}` })
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,
}
}
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),
// The mock is computed locally; it is not a cached fallback from the Go API.
cached: false,
}
return apiRequest<ForecastResponse>('/api/forecast', {
query: { sensor, horizon, scenario },
})
})