Skip to content

Commit e8f441c

Browse files
committed
add option to listen on unix domain socket
This adds a CLI argument --socket, that takes a path. The server will bind this path instead of a TCP port. closes gitpod-io#144
1 parent 0ce3bc5 commit e8f441c

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/vs/server/node/server.main.ts

+23-16
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,13 @@ async function handleFetchCallback(req: http.IncomingMessage, res: http.ServerRe
302302
interface ServerParsedArgs extends NativeParsedArgs {
303303
port?: string
304304
host?: string
305+
socket?: string
305306
}
306307
const SERVER_OPTIONS: OptionDescriptions<ServerParsedArgs> = {
307308
...OPTIONS,
308309
port: { type: 'string' },
309-
host: { type: 'string' }
310+
host: { type: 'string' },
311+
socket: { type: 'string' }
310312
};
311313

312314
export interface IStartServerResult {
@@ -1008,25 +1010,30 @@ export async function main(options: IServerOptions): Promise<void> {
10081010
});
10091011
});
10101012

1011-
let port = 3000;
1012-
if (parsedArgs.port) {
1013-
port = Number(parsedArgs.port);
1014-
} else if (typeof options.port === 'number') {
1015-
port = options.port;
1016-
}
1017-
1018-
const host = parsedArgs.host || '0.0.0.0';
1019-
server.on('error', () => {
1020-
server.close();
1021-
process.exit(1);
1022-
});
1023-
1024-
server.listen(port, host, () => {
1013+
const listeningListener = () => {
10251014
const addressInfo = server.address() as net.AddressInfo;
10261015
const address = addressInfo.address === '0.0.0.0' || addressInfo.address === '127.0.0.1' ? 'localhost' : addressInfo.address;
10271016
const formattedPort = addressInfo.port === 80 ? '' : String(addressInfo.port);
10281017
logService.info(`Web UI available at http://${address}:${formattedPort}`);
1029-
});
1018+
};
1019+
1020+
if (parsedArgs.socket) {
1021+
server.listen(parsedArgs.socket, listeningListener);
1022+
} else {
1023+
let port = 3000;
1024+
if (parsedArgs.port) {
1025+
port = Number(parsedArgs.port);
1026+
} else if (typeof options.port === 'number') {
1027+
port = options.port;
1028+
}
1029+
1030+
const host = parsedArgs.host || '0.0.0.0';
1031+
server.on('error', () => {
1032+
server.close();
1033+
process.exit(1);
1034+
});
1035+
server.listen(port, host, listeningListener);
1036+
}
10301037

10311038
});
10321039
}

0 commit comments

Comments
 (0)