@tenux/cli 0.0.23 → 0.0.25
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/cli.js +34 -9
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -503,9 +503,22 @@ function connectTunnel(instanceId, localPort, accessToken, userId) {
|
|
|
503
503
|
console.log(chalk2.green("\u2713"), `[tunnel] Connected: ${tunnelUrl}`);
|
|
504
504
|
});
|
|
505
505
|
ws.on("message", (data) => {
|
|
506
|
-
|
|
506
|
+
let ab;
|
|
507
|
+
if (data instanceof ArrayBuffer) {
|
|
508
|
+
ab = data;
|
|
509
|
+
} else if (Buffer.isBuffer(data)) {
|
|
510
|
+
ab = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
511
|
+
} else {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
507
514
|
handleRelayMessage(conn, ab);
|
|
508
515
|
});
|
|
516
|
+
ws.on("unexpected-response", (_req, res) => {
|
|
517
|
+
console.log(chalk2.red("\u2717"), `[tunnel] Upgrade rejected (HTTP ${res.statusCode})`);
|
|
518
|
+
if (!conn.closed) {
|
|
519
|
+
conn.reconnectTimer = setTimeout(connect, 5e3);
|
|
520
|
+
}
|
|
521
|
+
});
|
|
509
522
|
ws.on("close", () => {
|
|
510
523
|
if (conn.closed) return;
|
|
511
524
|
console.log(chalk2.yellow("!"), `[tunnel] Disconnected, reconnecting in 3s...`);
|
|
@@ -746,12 +759,24 @@ async function handleServerStart(command, supabase) {
|
|
|
746
759
|
console.log(chalk3.dim(` cwd: ${fullPath}`));
|
|
747
760
|
const { data: sessionData } = await supabase.auth.getSession();
|
|
748
761
|
const accessToken = sessionData?.session?.access_token ?? "";
|
|
749
|
-
const
|
|
750
|
-
|
|
762
|
+
const configuredPort = payload.port;
|
|
763
|
+
const env = {
|
|
764
|
+
...process.env,
|
|
765
|
+
FORCE_COLOR: "0"
|
|
766
|
+
};
|
|
767
|
+
if (configuredPort) {
|
|
768
|
+
env.PORT = String(configuredPort);
|
|
769
|
+
console.log(chalk3.dim(` PORT=${configuredPort}`));
|
|
770
|
+
} else {
|
|
771
|
+
delete env.PORT;
|
|
772
|
+
}
|
|
751
773
|
delete env.NODE_OPTIONS;
|
|
752
774
|
const parts = payload.command.split(/\s+/).filter(Boolean);
|
|
753
775
|
const bin = parts[0];
|
|
754
|
-
|
|
776
|
+
let cmdArgs = parts.slice(1);
|
|
777
|
+
if (configuredPort && !cmdArgs.some((a) => a === "--port" || a === "-p")) {
|
|
778
|
+
cmdArgs = [...cmdArgs, "--port", String(configuredPort)];
|
|
779
|
+
}
|
|
755
780
|
const isWindows = process.platform === "win32";
|
|
756
781
|
const child = spawn2(bin, cmdArgs, {
|
|
757
782
|
cwd: fullPath,
|
|
@@ -842,19 +867,19 @@ async function handleServerStart(command, supabase) {
|
|
|
842
867
|
}).eq("id", instance.id);
|
|
843
868
|
setTimeout(async () => {
|
|
844
869
|
if (!detectedPort) {
|
|
845
|
-
const
|
|
846
|
-
if (
|
|
847
|
-
managed.detectedPort =
|
|
870
|
+
const configuredPort2 = payload.port;
|
|
871
|
+
if (configuredPort2) {
|
|
872
|
+
managed.detectedPort = configuredPort2;
|
|
848
873
|
const tunnelUrl = connectTunnel(
|
|
849
874
|
instance.id,
|
|
850
|
-
|
|
875
|
+
configuredPort2,
|
|
851
876
|
accessToken,
|
|
852
877
|
command.user_id
|
|
853
878
|
);
|
|
854
879
|
managed.tunnelUrl = tunnelUrl;
|
|
855
880
|
await supabase.from("server_instances").update({
|
|
856
881
|
status: "running",
|
|
857
|
-
detected_port:
|
|
882
|
+
detected_port: configuredPort2,
|
|
858
883
|
tunnel_url: tunnelUrl,
|
|
859
884
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
860
885
|
}).eq("id", instance.id);
|