Skip to content

Commit d073622

Browse files
kylecarbscode-asher
authored andcommitted
Add --socket flag (#564)
* Add --socket flag * Add msg for already bound socket
1 parent 5f40ebb commit d073622

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/server/src/cli.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ commander.version(process.env.VERSION || "development")
3030
.option("-H, --allow-http", "Allow http connections.", false)
3131
.option("-P, --password <value>", "DEPRECATED: Use the PASSWORD environment variable instead. Specify a password for authentication.")
3232
.option("--disable-telemetry", "Disables ALL telemetry.", false)
33+
.option("--socket <value>", "Listen on a UNIX socket. Host and port will be ignored when set.")
3334
.option("--install-extension <value>", "Install an extension by its ID.")
3435
.option("--bootstrap-fork <name>", "Used for development. Never set.")
3536
.option("--extra-args <args>", "Used for development. Never set.")
@@ -63,6 +64,7 @@ const bold = (text: string | number): string | number => {
6364
readonly open?: boolean;
6465
readonly cert?: string;
6566
readonly certKey?: string;
67+
readonly socket?: string;
6668

6769
readonly installExtension?: string;
6870

@@ -267,7 +269,11 @@ const bold = (text: string | number): string | number => {
267269
});
268270

269271
logger.info("Starting webserver...", field("host", options.host), field("port", options.port));
270-
app.server.listen(options.port, options.host);
272+
if (options.socket) {
273+
app.server.listen(options.socket);
274+
} else {
275+
app.server.listen(options.port, options.host);
276+
}
271277
let clientId = 1;
272278
app.wss.on("connection", (ws, req) => {
273279
const id = clientId++;
@@ -284,7 +290,11 @@ const bold = (text: string | number): string | number => {
284290
});
285291
app.wss.on("error", (err: NodeJS.ErrnoException) => {
286292
if (err.code === "EADDRINUSE") {
287-
logger.error(`Port ${bold(options.port)} is in use. Please free up port ${options.port} or specify a different port with the -p flag`);
293+
if (options.socket) {
294+
logger.error(`Socket ${bold(options.socket)} is in use. Please specify a different socket.`);
295+
} else {
296+
logger.error(`Port ${bold(options.port)} is in use. Please free up port ${options.port} or specify a different port with the -p flag`);
297+
}
288298
process.exit(1);
289299
}
290300
});

0 commit comments

Comments
 (0)