Skip to content

Commit 0f883b5

Browse files
committed
🤖 feat: add -h and -p flags for server host/port configuration
Allows users to specify which host and port to bind to when running in server mode, instead of hardcoding 0.0.0.0:3000. Usage: node dist/main.js server # default: 0.0.0.0:3000 node dist/main.js server -h localhost # bind to localhost only node dist/main.js server -h 0.0.0.0 -p 8080 # custom port Defaults to 0.0.0.0:3000 for network accessibility. _Generated with `cmux`_
1 parent 2420b5d commit 0f883b5

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/main-server.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/**
22
* HTTP/WebSocket Server for cmux
33
* Allows accessing cmux backend from mobile devices
4+
*
5+
* Usage: node dist/main.js server [-h HOST] [-p PORT]
6+
* Options:
7+
* -h HOST Bind to specific host (default: 0.0.0.0)
8+
* -p PORT Bind to specific port (default: 3000)
49
*/
510
import { Config } from "./config";
611
import { IPC_CHANNELS } from "@/constants/ipc-constants";
@@ -13,6 +18,22 @@ import * as path from "path";
1318
import type { RawData } from "ws";
1419
import { WebSocket, WebSocketServer } from "ws";
1520

21+
// Parse command line arguments
22+
const args = process.argv.slice(3); // Skip node, script, and "server"
23+
let HOST = "0.0.0.0";
24+
let PORT = 3000;
25+
26+
for (let i = 0; i < args.length; i++) {
27+
const arg = args[i];
28+
if (arg === "-h" && i + 1 < args.length) {
29+
HOST = args[i + 1];
30+
i++; // Skip next arg since we consumed it
31+
} else if (arg === "-p" && i + 1 < args.length) {
32+
PORT = parseInt(args[i + 1], 10);
33+
i++;
34+
}
35+
}
36+
1637
// Mock Electron's ipcMain for HTTP
1738
class HttpIpcMainAdapter {
1839
private handlers = new Map<string, (event: unknown, ...args: unknown[]) => Promise<unknown>>();
@@ -232,6 +253,6 @@ wss.on("connection", (ws) => {
232253
});
233254
});
234255

235-
server.listen(3000, () => {
236-
console.log("Server is running on port 3000");
256+
server.listen(PORT, HOST, () => {
257+
console.log(`Server is running on http://${HOST}:${PORT}`);
237258
});

0 commit comments

Comments
 (0)