File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -147,3 +147,41 @@ const defaultDispatcher = new Agent({
147147
148148setGlobalDispatcher (defaultDispatcher) // Add these interceptors to all `fetch` and Undici `request` calls
149149```
150+
151+ ## Connecting via Unix domain sockets (UDS)
152+
153+ ### request() over UDS (per-call dispatcher)
154+ ``` js
155+ const { Agent , request } = require (' undici' )
156+
157+ async function requestOverUds () {
158+ const uds = new Agent ({ connect: { socketPath: ' /var/run/docker.sock' } })
159+ try {
160+ const { statusCode , headers , body } = await request (' http://localhost/_ping' , {
161+ dispatcher: uds
162+ })
163+ console .log (statusCode, headers, await body .text ())
164+ } finally {
165+ await uds .close ()
166+ }
167+ }
168+ ```
169+
170+ ### fetch() over UDS (per-call dispatcher)
171+ ``` js
172+ const { Agent , fetch } = require (' undici' )
173+
174+ async function fetchOverUds () {
175+ const uds = new Agent ({ connect: { socketPath: ' /var/run/docker.sock' } })
176+ try {
177+ const res = await fetch (' http://localhost/containers/json' , { dispatcher: uds })
178+ console .log (res .status , await res .text ())
179+ } finally {
180+ await uds .close ()
181+ }
182+ }
183+ ```
184+
185+ > Note
186+ > - ` connect.socketPath ` must be the exact filesystem path your server listens on (e.g., Docker: ` /var/run/docker.sock ` )..
187+ > - Not supported on Windows (uses named pipes instead).
You can’t perform that action at this time.
0 commit comments