midsomar 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -3
- package/dist/server.js +5 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -51,9 +51,6 @@ async function cmdWeb(args) {
|
|
|
51
51
|
}
|
|
52
52
|
process.stdout.write("starting...\n");
|
|
53
53
|
const engine = await startEngine({ password });
|
|
54
|
-
if (process.env.MIDSOMAR_DEBUG) {
|
|
55
|
-
process.stdout.write(`\n engine: ${engine.url}\n`);
|
|
56
|
-
}
|
|
57
54
|
const uiDir = new URL("../web-ui", import.meta.url).pathname;
|
|
58
55
|
const ui = await serveUI({
|
|
59
56
|
uiDir,
|
package/dist/server.js
CHANGED
|
@@ -63,10 +63,11 @@ function findBinary() {
|
|
|
63
63
|
}
|
|
64
64
|
throw new Error("engine binary not found");
|
|
65
65
|
}
|
|
66
|
+
const ENGINE_PORT = 4096;
|
|
67
|
+
const ENGINE_URL = `http://127.0.0.1:${ENGINE_PORT}`;
|
|
66
68
|
export function startEngine(opts = {}) {
|
|
67
69
|
return new Promise((resolvePromise, reject) => {
|
|
68
70
|
const binary = findBinary();
|
|
69
|
-
const port = opts.port ?? 0;
|
|
70
71
|
const password = opts.password || "";
|
|
71
72
|
if (!existsSync(LOG_DIR))
|
|
72
73
|
mkdirSync(LOG_DIR, { recursive: true });
|
|
@@ -78,7 +79,7 @@ export function startEngine(opts = {}) {
|
|
|
78
79
|
const xdgCache = join(MIDSOMAR_HOME, "cache");
|
|
79
80
|
for (const d of [xdgData, xdgConfig, xdgState, xdgCache])
|
|
80
81
|
mkdirSync(d, { recursive: true });
|
|
81
|
-
const proc = spawn(binary, ["serve", "--port", String(
|
|
82
|
+
const proc = spawn(binary, ["serve", "--port", String(ENGINE_PORT), "--cors", "*"], {
|
|
82
83
|
stdio: ["ignore", "pipe", "pipe"],
|
|
83
84
|
env: {
|
|
84
85
|
...process.env,
|
|
@@ -89,27 +90,11 @@ export function startEngine(opts = {}) {
|
|
|
89
90
|
OPENCODE_SERVER_PASSWORD: password,
|
|
90
91
|
},
|
|
91
92
|
});
|
|
92
|
-
|
|
93
|
-
const onData = (d) => {
|
|
94
|
-
appendFileSync(logFile, d);
|
|
95
|
-
const m = d.toString().match(/http:\/\/[^\s]+:(\d+)/);
|
|
96
|
-
if (m && !capturedUrl)
|
|
97
|
-
capturedUrl = `http://127.0.0.1:${m[1]}`;
|
|
98
|
-
};
|
|
93
|
+
const onData = (d) => appendFileSync(logFile, d);
|
|
99
94
|
proc.stdout.on("data", onData);
|
|
100
95
|
proc.stderr.on("data", onData);
|
|
101
96
|
proc.on("error", (err) => reject(new Error(`engine: ${err.message}`)));
|
|
102
|
-
|
|
103
|
-
const poll = () => {
|
|
104
|
-
if (capturedUrl)
|
|
105
|
-
return resolvePromise({ url: capturedUrl, kill: () => proc.kill() });
|
|
106
|
-
if (Date.now() - start > 15_000) {
|
|
107
|
-
proc.kill();
|
|
108
|
-
return reject(new Error("engine did not start"));
|
|
109
|
-
}
|
|
110
|
-
setTimeout(poll, 200);
|
|
111
|
-
};
|
|
112
|
-
setTimeout(poll, 500);
|
|
97
|
+
setTimeout(() => resolvePromise({ url: ENGINE_URL, kill: () => proc.kill() }), 1000);
|
|
113
98
|
});
|
|
114
99
|
}
|
|
115
100
|
function serveFile(filePath, res) {
|