MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / startStaticServer

Function startStaticServer

scripts/dev-static.mjs:452–510  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

450}
451
452function startStaticServer(config) {
453 // Reuse `vitePort` as the upstream port name so the ingress route table
454 // below stays identical to dev-with-automation.mjs.
455 logService("static", `Starting on port ${config.vitePort}...`, c.magenta);
456
457 // Mirror the proxy targets that vite.config.ts exposes in dev mode so that
458 // hitting :3001 directly behaves like Vite's dev server (e.g. /server_info
459 // is forwarded to the agent-server instead of falling back to the SPA
460 // shell). Without this, /server_info on :3001 returns index.html.
461 const staticServerScript = join(projectRoot, "scripts", "static-server.mjs");
462 const runtimeServicesInfo = JSON.stringify(
463 buildAutomationRuntimeServicesInfo({
464 ...config,
465 frontendKind: "static",
466 }),
467 );
468 const keyPolicy = applySessionKeyPolicy({
469 host: config.bindHost,
470 allowLanSessionKey: config.allowLanSessionKey,
471 sessionApiKey: config.sessionApiKey,
472 warn: (msg) => logService("static", msg, c.yellow),
473 });
474 spawnService(
475 "static",
476 "node",
477 [
478 staticServerScript,
479 "--dir",
480 join(config.canvasPath, "build"),
481 "--port",
482 String(config.vitePort),
483 ...bindHostArgs(config.bindHost),
484 ...(process.env.VITE_BASE_PATH
485 ? ["--base-path", process.env.VITE_BASE_PATH]
486 : []),
487 ...(keyPolicy.sessionApiKey && config.allowLanSessionKey
488 ? ["--allow-lan-session-key"]
489 : []),
490 ...(keyPolicy.authRequired ? ["--auth-required"] : []),
491 "--runtime-services-info",
492 runtimeServicesInfo,
493 ...buildLocalServiceRouteArgs(config),
494 // Only the static server injects into the document, so only it can tell
495 // the frontend this origin serves the editor. The ingress below routes
496 // the same prefix but proxies the HTML through untouched.
497 ...getVSCodeAdvertiseArgs(config),
498 ...getNoReferrerPrefixArgs(config),
499 ],
500 {
501 cwd: config.canvasPath,
502 color: c.magenta,
503 // Clear an inherited key if policy forbids injecting it.
504 env: {
505 ...buildMarsWebEnv("static", config),
506 SESSION_API_KEY: keyPolicy.sessionApiKey || "",
507 },
508 },
509 );

Callers 9

startServerFunction · 0.90
startServerAdvertisingFunction · 0.90
startServerLockedToCloudFunction · 0.90
startServerWithKeyFunction · 0.90
startFunction · 0.90
mainFunction · 0.70

Calls 9

applySessionKeyPolicyFunction · 0.90
bindHostArgsFunction · 0.90
getVSCodeAdvertiseArgsFunction · 0.90
getNoReferrerPrefixArgsFunction · 0.90
logServiceFunction · 0.70
spawnServiceFunction · 0.70
buildMarsWebEnvFunction · 0.70

Tested by 6

startServerFunction · 0.72
startServerAdvertisingFunction · 0.72
startServerLockedToCloudFunction · 0.72
startServerWithKeyFunction · 0.72
startFunction · 0.72