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

Is fetch API planned to support unix domain socket? #2970

Open
JerrysShan opened this issue Mar 18, 2024 · 5 comments
Open

Is fetch API planned to support unix domain socket? #2970

JerrysShan opened this issue Mar 18, 2024 · 5 comments

Comments

@JerrysShan
Copy link

Many Node.js applications leverage Unix Domain Sockets for inter-process communication (IPC), providing a more efficient and secure way to communicate compared to traditional network sockets. Supporting the socketPath option in undici's fetch API could significantly benefit applications that rely on IPC, especially those dealing with microservices or local server communication.

it would be incredibly useful to have fetch requests directed to a Unix Domain Socket. This could look something like:

const response = await fetch('unix:///path/to/socket.sock/request-path', {
  method: 'GET'
  // additional options
});

@ronag
Copy link
Member

ronag commented Mar 18, 2024

Unlikely. We are only doing web spec stuff. If you are doing backend development why are you using fetch? Use undici.request and then you can use unix sockets.

@JerrysShan
Copy link
Author

Unlikely. We are only doing web spec stuff. If you are doing backend development why are you using fetch? Use undici.request and then you can use unix sockets.

Because the fetch API is familiar to most developers, we also use the same API as the web on the server side.

@mcollina
Copy link
Member

I think supporting this should be easy enough and possibly just having the request pass the validation check.

@KhafraDev wdyt?

@KhafraDev
Copy link
Member

I'm not opposed to it, as long as it doesn't add an option to fetch

@KhafraDev
Copy link
Member

KhafraDev commented Mar 20, 2024

in the meantime, you can use Agent with fetch

import { fetch, Agent } from 'undici'

const resp = await fetch('http://localhost/version', {
  dispatcher: new Agent({
    connect: {
      socketPath: '/var/run/docker.sock'
    }
  })
})

console.log(await resp.text())

as a sidenote this is actually how people seem to fetch unix sockets in deno

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

4 participants