| 402 | } |
| 403 | |
| 404 | function startStaticServer(config) { |
| 405 | // Reuse `vitePort` as the upstream port name so the ingress route table |
| 406 | // below stays identical to dev-with-automation.mjs. |
| 407 | logService("static", `Starting on port ${config.vitePort}...`, c.magenta); |
| 408 | |
| 409 | // Mirror the proxy targets that vite.config.ts exposes in dev mode so that |
| 410 | // hitting :3001 directly behaves like Vite's dev server (e.g. /server_info |
| 411 | // is forwarded to the agent-server instead of falling back to the SPA |
| 412 | // shell). Without this, /server_info on :3001 returns index.html. |
| 413 | const staticServerScript = join(projectRoot, "scripts", "static-server.mjs"); |
| 414 | const runtimeServicesInfo = JSON.stringify( |
| 415 | buildAutomationRuntimeServicesInfo({ |
| 416 | ...config, |
| 417 | frontendKind: "static", |
| 418 | }), |
| 419 | ); |
| 420 | spawnService( |
| 421 | "static", |
| 422 | "node", |
| 423 | [ |
| 424 | staticServerScript, |
| 425 | "--dir", |
| 426 | join(config.canvasPath, "build"), |
| 427 | "--port", |
| 428 | String(config.vitePort), |
| 429 | ...(process.env.VITE_BASE_PATH |
| 430 | ? ["--base-path", process.env.VITE_BASE_PATH] |
| 431 | : []), |
| 432 | // Inject the API key so the pre-built frontend can authenticate |
| 433 | // to the agent-server without a baked-in VITE_SESSION_API_KEY. |
| 434 | ...(config.sessionApiKey |
| 435 | ? ["--session-api-key", config.sessionApiKey] |
| 436 | : []), |
| 437 | "--runtime-services-info", |
| 438 | runtimeServicesInfo, |
| 439 | ...buildLocalServiceRouteArgs(config), |
| 440 | // Only the static server injects into the document, so only it can tell |
| 441 | // the frontend this origin serves the editor. The ingress below routes |
| 442 | // the same prefix but proxies the HTML through untouched. |
| 443 | ...getVSCodeAdvertiseArgs(config), |
| 444 | ...getNoReferrerPrefixArgs(config), |
| 445 | ], |
| 446 | { |
| 447 | cwd: config.canvasPath, |
| 448 | color: c.magenta, |
| 449 | }, |
| 450 | ); |
| 451 | } |
| 452 | |
| 453 | function startIngress(config) { |
| 454 | logService("ingress", `Starting on port ${config.ingressPort}...`, c.yellow); |