Open JerrysShan opened 8 months ago
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.
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.
I think supporting this should be easy enough and possibly just having the request pass the validation check.
@KhafraDev wdyt?
I'm not opposed to it, as long as it doesn't add an option to fetch
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
If adding an option to fetch is problematic for some reason, how about just handling requests to unix://
in Deno itself, forwarding the request to the socket? To avoid name resolution/SNI issues, users could include an explicit Host
header with their request that would need to be evaluated prior to dispatching.
I know this isn't really elegant from the implementation perspective, but it'd solve the problem now without any API changes necessary, and works just like people would expect it to.
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: