Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for binding to an IPC server #18

Open
shirhatti opened this issue Jun 6, 2024 · 0 comments
Open

Add support for binding to an IPC server #18

shirhatti opened this issue Jun 6, 2024 · 0 comments

Comments

@shirhatti
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant