vs-rest-api
vs-rest-api copied to clipboard
Add support for binding to an IPC server
The net
module in node allows you to create a TCP or IPC server, AF_UNIX sockets on *nix and named pipes on Windows. Using an AF_UNIX socket is generally easier to secure as connecting to a stream socket requires write permission to the socket. In comparison a loopback TCP server can be connected to by any process on the server.
Sample code snippet on how to bind to an AF_UNIX socket:
const SOCKET_PATH = '/tmp/vscode-socket';
// Check if the socket file already exists and delete it if it does
if (fs.existsSync(SOCKET_PATH)) {
fs.unlinkSync(SOCKET_PATH);
}
// Listen on Unix socket
server.listen(SOCKET_PATH, () => {
console.log(`HTTP server listening on ${SOCKET_PATH}`);
});
And you can make a request against it using something like this:
curl --unix-socket /tmp/vscode-socket -X GET http://localhost/api/editor
Would you consider adding support for AF_UNIX sockets? Or be willing to accept a contribution?