- 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
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { apiForward, isMockMode } from '../utils/api'
|
|
import { createMockTrainJob } from '../utils/train-jobs'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
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
|
|
}
|
|
}
|
|
} 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,
|
|
})
|
|
})
|