-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
41 lines (33 loc) · 1002 Bytes
/
cli.ts
File metadata and controls
41 lines (33 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
import { ZigoxyClient } from "./client";
const usage = `
Usage: zigoxy <local-port>
Example:
zigoxy 8080 # Exposes localhost:8080 via zigoxy server
`;
const cli = async () => {
const localPort = parseInt(process.argv[2]);
if (!localPort || isNaN(localPort)) {
console.error("Error: Please provide a valid port number");
console.log(usage);
process.exit(1);
}
const client = new ZigoxyClient({
serverHost: process.env.ZIGOXY_SERVER_HOST || "localhost",
serverPort: parseInt(process.env.ZIGOXY_SERVER_PORT || "3000"),
localPort: localPort,
secure: false,
});
try {
await client.connect();
process.on("SIGINT", () => {
console.log("\n👋 Shutting down zigoxy client...");
client.disconnect();
process.exit(0);
});
} catch (err) {
console.error("❌ Failed to connect:", err);
process.exit(1);
}
};
cli();