nomadexapp 0.2.4 → 0.2.5
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/bin/nomadex.mjs +52 -3
- package/package.json +1 -1
package/bin/nomadex.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { createServer } from "node:http";
|
|
3
|
+
import { createServer, request as httpRequest } from "node:http";
|
|
4
4
|
import { statSync, readFileSync, existsSync, realpathSync } from "node:fs";
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
|
+
import { request as httpsRequest } from "node:https";
|
|
6
7
|
import net from "node:net";
|
|
7
8
|
import os from "node:os";
|
|
8
9
|
import path from "node:path";
|
|
@@ -667,15 +668,63 @@ const confirmAlternatePort = async (message) => {
|
|
|
667
668
|
}
|
|
668
669
|
};
|
|
669
670
|
|
|
671
|
+
const isCodexWebSocketReady = () =>
|
|
672
|
+
new Promise((resolve) => {
|
|
673
|
+
const request = wsUrl.protocol === "wss:" ? httpsRequest : httpRequest;
|
|
674
|
+
let settled = false;
|
|
675
|
+
const finish = (value) => {
|
|
676
|
+
if (settled) {
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
settled = true;
|
|
680
|
+
resolve(value);
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
const requestOptions = {
|
|
684
|
+
protocol: wsUrl.protocol === "wss:" ? "https:" : "http:",
|
|
685
|
+
hostname: getWsHost(),
|
|
686
|
+
port: getWsPort(),
|
|
687
|
+
path: wsUrl.pathname || "/",
|
|
688
|
+
headers: {
|
|
689
|
+
Connection: "Upgrade",
|
|
690
|
+
Upgrade: "websocket",
|
|
691
|
+
"Sec-WebSocket-Key": randomBytes(16).toString("base64"),
|
|
692
|
+
"Sec-WebSocket-Version": "13",
|
|
693
|
+
},
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const req = request(requestOptions);
|
|
697
|
+
req.setTimeout(500, () => {
|
|
698
|
+
req.destroy();
|
|
699
|
+
finish(false);
|
|
700
|
+
});
|
|
701
|
+
req.on("upgrade", (_response, socket) => {
|
|
702
|
+
socket.destroy();
|
|
703
|
+
finish(true);
|
|
704
|
+
});
|
|
705
|
+
req.on("response", (response) => {
|
|
706
|
+
response.resume();
|
|
707
|
+
finish(false);
|
|
708
|
+
});
|
|
709
|
+
req.on("error", () => {
|
|
710
|
+
finish(false);
|
|
711
|
+
});
|
|
712
|
+
req.end();
|
|
713
|
+
});
|
|
714
|
+
|
|
670
715
|
const isCodexAppServerReady = async () => {
|
|
671
716
|
try {
|
|
672
717
|
const response = await fetch(getReadyzUrl(), {
|
|
673
718
|
signal: AbortSignal.timeout(500),
|
|
674
719
|
});
|
|
675
|
-
|
|
720
|
+
if (response.ok) {
|
|
721
|
+
return true;
|
|
722
|
+
}
|
|
676
723
|
} catch {
|
|
677
|
-
|
|
724
|
+
// Some Codex builds only expose the websocket endpoint, not /readyz.
|
|
678
725
|
}
|
|
726
|
+
|
|
727
|
+
return isCodexWebSocketReady();
|
|
679
728
|
};
|
|
680
729
|
|
|
681
730
|
const ensureUiPortAvailable = async () => {
|