/** * Dev runner: starts the CMS API (server/index.mjs) and the Vite dev server * together, so /admin can publish while you work on the site. * * npm run dev → API on 8787, site on 5173 (or $PORT) * npm run dev:web → Vite only (site reads factory content) * npm run dev:api → API only */ import { spawn } from 'node:child_process' import path from 'node:path' const ROOT = path.resolve(import.meta.dirname, '..') const API_PORT = process.env.API_PORT || '8787' const children = [] // Both processes are plain Node scripts, launched without a shell so paths with // spaces (C:\Program Files\nodejs\node.exe) are passed through intact. function run(name, args, env) { const child = spawn(process.execPath, args, { cwd: ROOT, stdio: ['ignore', 'inherit', 'inherit'], env: { ...process.env, ...env }, }) child.on('exit', (code) => { if (code) console.error(`[${name}] exited with ${code}`) shutdown() }) children.push(child) return child } let closing = false function shutdown() { if (closing) return closing = true for (const child of children) child.kill() } process.on('SIGINT', shutdown) process.on('SIGTERM', shutdown) run('api', ['server/index.mjs'], { PORT: API_PORT }) run('web', ['node_modules/vite/bin/vite.js'], { API_URL: `http://localhost:${API_PORT}` })