Skip to content

Instantly share code, notes, and snippets.

@RafaelGSS
Created March 15, 2023 20:52
Show Gist options
  • Save RafaelGSS/5c27d92b6c85017791d73562387af347 to your computer and use it in GitHub Desktop.
Save RafaelGSS/5c27d92b6c85017791d73562387af347 to your computer and use it in GitHub Desktop.
Example custom connect fetch
const { setGlobalDispatcher, Agent } = require('undici')
setGlobalDispatcher(
new Agent({
connect: (opts) => {
console.log('Called with', opts)
// implement custom dns lookup
}
})
)
fetch('https://example.com')
// ➜ test node index.js
//Called with {
// host: 'example.com',
// hostname: 'example.com',
// protocol: 'https:',
// port: '',
// servername: null,
// localAddress: null
//}
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment