From d07362262966e0011aec7268b01dded3a9df0ad5 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Mon, 22 Apr 2019 12:47:27 -0500 Subject: [PATCH] Add --socket flag (#564) * Add --socket flag * Add msg for already bound socket --- packages/server/src/cli.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts index 118ddb5a4..9d91b6723 100644 --- a/packages/server/src/cli.ts +++ b/packages/server/src/cli.ts @@ -30,6 +30,7 @@ commander.version(process.env.VERSION || "development") .option("-H, --allow-http", "Allow http connections.", false) .option("-P, --password ", "DEPRECATED: Use the PASSWORD environment variable instead. Specify a password for authentication.") .option("--disable-telemetry", "Disables ALL telemetry.", false) + .option("--socket ", "Listen on a UNIX socket. Host and port will be ignored when set.") .option("--install-extension ", "Install an extension by its ID.") .option("--bootstrap-fork ", "Used for development. Never set.") .option("--extra-args ", "Used for development. Never set.") @@ -63,6 +64,7 @@ const bold = (text: string | number): string | number => { readonly open?: boolean; readonly cert?: string; readonly certKey?: string; + readonly socket?: string; readonly installExtension?: string; @@ -267,7 +269,11 @@ const bold = (text: string | number): string | number => { }); logger.info("Starting webserver...", field("host", options.host), field("port", options.port)); - app.server.listen(options.port, options.host); + if (options.socket) { + app.server.listen(options.socket); + } else { + app.server.listen(options.port, options.host); + } let clientId = 1; app.wss.on("connection", (ws, req) => { const id = clientId++; @@ -284,7 +290,11 @@ const bold = (text: string | number): string | number => { }); app.wss.on("error", (err: NodeJS.ErrnoException) => { if (err.code === "EADDRINUSE") { - logger.error(`Port ${bold(options.port)} is in use. Please free up port ${options.port} or specify a different port with the -p flag`); + if (options.socket) { + logger.error(`Socket ${bold(options.socket)} is in use. Please specify a different socket.`); + } else { + logger.error(`Port ${bold(options.port)} is in use. Please free up port ${options.port} or specify a different port with the -p flag`); + } process.exit(1); } });