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

+46 -24
View File
@@ -1,34 +1,56 @@
import { apiForward, isMockMode } from '../utils/api'
import { createMockTrainJob } from '../utils/train-jobs'
export default defineEventHandler(async (event) => {
let model: 'small' | 'forecast' = 'small'
let filename: string | null = null
if (isMockMode()) {
let model: 'small' | 'forecast' = 'small'
let filename: string | null = null
const contentType = getRequestHeader(event, 'content-type') ?? ''
if (contentType.includes('multipart/form-data')) {
const parts = await readMultipartFormData(event)
for (const part of parts ?? []) {
if (part.name === 'model' && part.data) {
const value = part.data.toString()
if (value === 'small' || value === 'forecast') model = value
}
if (part.name === 'file' && part.filename) {
filename = part.filename
const contentType = getRequestHeader(event, 'content-type') ?? ''
if (contentType.includes('multipart/form-data')) {
const parts = await readMultipartFormData(event)
for (const part of parts ?? []) {
if (part.name === 'model' && part.data) {
const value = part.data.toString()
if (value === 'small' || value === 'forecast') model = value
}
if (part.name === 'file' && part.filename) {
filename = part.filename
}
}
} else {
const body = await readBody<{ model?: 'small' | 'forecast'; path?: string }>(event).catch(() => null)
if (body?.model === 'small' || body?.model === 'forecast') model = body.model
if (body?.path) filename = body.path
}
const job = createMockTrainJob(model, filename)
setResponseStatus(event, 202)
return {
job_id: job.job_id,
status: job.status,
model: job.model,
submitted_at: job.started_at,
mock: true,
}
} else {
const body = await readBody<{ model?: 'small' | 'forecast'; path?: string }>(event).catch(() => null)
if (body?.model === 'small' || body?.model === 'forecast') model = body.model
if (body?.path) filename = body.path
}
const job = createMockTrainJob(model, filename)
setResponseStatus(event, 202)
return {
job_id: job.job_id,
status: job.status,
model: job.model,
submitted_at: job.started_at,
mock: true,
// Stream the multipart CSV to Go unchanged. The control credentials are
// attached by the Nitro process and never reach the browser bundle.
const contentType = getRequestHeader(event, 'content-type') ?? ''
if (!contentType) {
throw createError({
statusCode: 400,
statusMessage: 'Content-Type must be application/json or multipart/form-data',
})
}
const body = await readRawBody(event)
return apiForward(event, '/api/train', {
method: 'POST',
body,
headers: { 'content-type': contentType },
control: true,
timeoutMs: 60_000,
})
})