Add --socket flag (#564)

* Add --socket flag

* Add msg for already bound socket
This commit is contained in:
Kyle Carberry 2019-04-22 12:47:27 -05:00 committed by Asher
parent 5f40ebb845
commit d073622629
1 changed files with 12 additions and 2 deletions

View File

@ -30,6 +30,7 @@ commander.version(process.env.VERSION || "development")
.option("-H, --allow-http", "Allow http connections.", false) .option("-H, --allow-http", "Allow http connections.", false)
.option("-P, --password <value>", "DEPRECATED: Use the PASSWORD environment variable instead. Specify a password for authentication.") .option("-P, --password <value>", "DEPRECATED: Use the PASSWORD environment variable instead. Specify a password for authentication.")
.option("--disable-telemetry", "Disables ALL telemetry.", false) .option("--disable-telemetry", "Disables ALL telemetry.", false)
.option("--socket <value>", "Listen on a UNIX socket. Host and port will be ignored when set.")
.option("--install-extension <value>", "Install an extension by its ID.") .option("--install-extension <value>", "Install an extension by its ID.")
.option("--bootstrap-fork <name>", "Used for development. Never set.") .option("--bootstrap-fork <name>", "Used for development. Never set.")
.option("--extra-args <args>", "Used for development. Never set.") .option("--extra-args <args>", "Used for development. Never set.")
@ -63,6 +64,7 @@ const bold = (text: string | number): string | number => {
readonly open?: boolean; readonly open?: boolean;
readonly cert?: string; readonly cert?: string;
readonly certKey?: string; readonly certKey?: string;
readonly socket?: string;
readonly installExtension?: 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)); 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; let clientId = 1;
app.wss.on("connection", (ws, req) => { app.wss.on("connection", (ws, req) => {
const id = clientId++; const id = clientId++;
@ -284,7 +290,11 @@ const bold = (text: string | number): string | number => {
}); });
app.wss.on("error", (err: NodeJS.ErrnoException) => { app.wss.on("error", (err: NodeJS.ErrnoException) => {
if (err.code === "EADDRINUSE") { 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); process.exit(1);
} }
}); });