MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / openStatic

Function openStatic

ts/workflow-cli/cli/open.ts:48–69  ·  view source on GitHub ↗

* STATIC: serve the bundled SPA (` /dist`, a sibling of this file's `dist-cli`) * plus the file bridge from a Node HTTP server on an ephemeral port, then open * the browser. No Vite, no source.

(resolvedFile?: string, allowRoot?: string)

Source from the content-addressed store, hash-verified

46 * the browser. No Vite, no source.
47 */
48async function openStatic(resolvedFile?: string, allowRoot?: string): Promise<void> {
49 const here = path.dirname(fileURLToPath(import.meta.url));
50 const spaRoot = path.resolve(here, "..", "dist");
51 if (!tryAccess(path.join(spaRoot, "index.html"))) {
52 process.stderr.write(`Built SPA not found at ${spaRoot}. This package is missing its bundled assets.\n`);
53 process.exit(1);
54 }
55
56 const allowedRoots = [allowRoot ?? process.cwd()];
57 const { port } = await startStaticServer({ spaRoot, allowedRoots });
58 const url = resolvedFile
59 ? `http://localhost:${port}/?file=${encodeURIComponent(resolvedFile)}`
60 : `http://localhost:${port}/`;
61
62 process.stdout.write(`\nfh-workflow running at ${url}\n`);
63 if (resolvedFile) process.stdout.write(`Bound to ${resolvedFile}\n`);
64 process.stdout.write("Press Ctrl+C to stop.\n\n");
65 openInBrowser(url);
66
67 // The listening server keeps the event loop alive; block until Ctrl+C.
68 await new Promise<never>(() => {});
69}
70
71/**
72 * DEV: spawn Vite as a child process (NOT via createServer in-process — Vite's

Callers 1

openCommandFunction · 0.85

Calls 4

startStaticServerFunction · 0.90
tryAccessFunction · 0.85
openInBrowserFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected