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

Function buildConfig

scripts/dev-with-automation.mjs:330–460  ·  view source on GitHub ↗
(args, env = process.env)

Source from the content-addressed store, hash-verified

328}
329
330async function buildConfig(args, env = process.env) {
331 // Apply args to env for buildAutomationCommand
332 if (args.automationGitRef) {
333 env.OH_AUTOMATION_GIT_REF = args.automationGitRef;
334 }
335 if (args.automationRepo) {
336 env.OH_AUTOMATION_REPO = args.automationRepo;
337 }
338
339 const frontendOnly = Boolean(args.frontendOnly);
340 const backendOnly = Boolean(args.backendOnly);
341 if (frontendOnly && backendOnly) {
342 throw new Error(
343 "--frontend-only and --backend-only cannot be used together",
344 );
345 }
346
347 const launchFrontend = !backendOnly;
348 const launchAgentServer = !frontendOnly;
349 const launchAutomation = !frontendOnly;
350 const isPublic = args.public;
351
352 if (isPublic && frontendOnly) {
353 throw new Error("--public cannot be used with --frontend-only");
354 }
355
356 // In public mode, LOCAL_BACKEND_API_KEY is required — without it the
357 // auth screen has nothing to validate against.
358 if (isPublic && !env.LOCAL_BACKEND_API_KEY) {
359 logError(
360 "PUBLIC MODE requires LOCAL_BACKEND_API_KEY environment variable.\n" +
361 " Example: LOCAL_BACKEND_API_KEY=my-secret npm run dev -- --public",
362 );
363 process.exit(1);
364 }
365
366 // Preferred ports (from env or defaults).
367 // OH_CANVAS_SAFE_BACKEND_PORT / OH_CANVAS_SAFE_AUTOMATION_PORT /
368 // OH_CANVAS_SAFE_VITE_PORT allow tests (and advanced users) to redirect
369 // internal service ports without affecting the production default.
370 const preferredIngressPort = args.port || parseInt(env.PORT, 10) || 8000;
371 const preferredBackendPort =
372 parseInt(env.OH_CANVAS_SAFE_BACKEND_PORT, 10) || DEFAULT_BACKEND_PORT;
373 const preferredAutomationPort =
374 parseInt(env.OH_CANVAS_SAFE_AUTOMATION_PORT, 10) || DEFAULT_AUTOMATION_PORT;
375 const preferredVitePort = parseInt(env.OH_CANVAS_SAFE_VITE_PORT, 10) || 3001;
376
377 // Fail fast if any preferred port for a service in this mode is already in use.
378 const requiredPorts = [{ name: "ingress", port: preferredIngressPort }];
379 if (launchAgentServer) {
380 requiredPorts.push({ name: "agent-server", port: preferredBackendPort });
381 }
382 if (launchAutomation) {
383 requiredPorts.push({ name: "automation", port: preferredAutomationPort });
384 }
385 if (launchFrontend) {
386 requiredPorts.push({ name: "frontend", port: preferredVitePort });
387 }

Callers 1

mainFunction · 0.70

Calls 5

assertPortsFreeFunction · 0.90
buildSafeDevConfigFunction · 0.90
logErrorFunction · 0.70
logStepFunction · 0.70
logServiceFunction · 0.70

Tested by

no test coverage detected