File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -126,17 +126,21 @@ async function deleteRequest (port = 3001) {
126126}
127127```
128128
129- ## Cacheable DNS Lookup
129+ ## Production configuration
130130
131- ### Using CacheableLookup to cache DNS lookups in undici
131+ ### Using interceptors to add response caching, DNS lookup caching and connection retries
132132
133133``` js
134- import { Agent } from ' undici'
135- import CacheableLookup from ' cacheable-lookup' ;
134+ import { Agent , interceptors , setGlobalDispatcher } from ' undici'
136135
137- const cacheable = new CacheableLookup (opts)
136+ // Interceptors to add response caching, DNS caching and retrying to the dispatcher
137+ const { cache , dns , retry } = interceptors
138138
139- const agent = new Agent ({
140- connect: { lookup: cacheable .lookup }
141- })
139+ const defaultDispatcher = new Agent ({
140+ connections: 100 , // Limit concurrent kept-alive connections to not run out of resources
141+ headersTimeout: 10_000 , // 10 seconds; set as appropriate for the remote servers you plan to connect to
142+ bodyTimeout: 10_000 ,
143+ }).compose (cache (), dns (), retry ())
144+
145+ setGlobalDispatcher (defaultDispatcher) // Add these interceptors to all `fetch` and Undici `request` calls
142146```
You can’t perform that action at this time.
0 commit comments