You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hard to find an example of a proxy that works with undici fetch. Tried 3 different proxy servers in Node.js which all work with axios for example but not with undici fetch.
Would be very helpful to add a simple proxy server example written in Node.js to test undici fetch with.
The implementation should look like...
A small code block in the README.md like the following
Simple proxy in Node.js to test undici fetch with:
import * as http from 'http';
import { createProxy } from 'proxy';
const PORT = 8000;
const server = createProxy(http.createServer());
server.on('request', (req, res) => {
console.log(`Incoming request to ${req.url}`);
});
server.listen(PORT, () => {
console.log('Proxy server listening on port', PORT);
});
Additional context
I want to migrate from axios to fetch (Windows 11, Node.js version 20.17.0) but i've tried 3 different proxies which all work (passing through the proxy and getting a response) with axios (or postman) but none with undici (version 6.19.8) fetch. Request to proxy1.js and proxy2.js never resolves or rejects while request to proxy3.js bypasses proxy completely and gets a response.
import*ashttpfrom'node:http'import{once}from'node:events'import{createProxy}from'proxy'import{ProxyAgent}from'./index.js'constproxyServer=createProxy(http.createServer())constserver=http.createServer((req,res)=>{res.writeHead(200,{'Content-Type': 'text/plain'})res.end('okay')})// proxyServer.on('request', (req, res) => {// console.log(`Incoming request to ${req.url}`)// })console.log('Listening...')awaitonce(proxyServer.listen(0),'listening')awaitonce(server.listen(0),'listening')const{port: proxyPort}=proxyServer.address()const{ port }=server.address()console.log(`Proxy listening on port ${proxyPort}`)console.log(`Server listening on port ${port}`);(async()=>{try{constagent=newProxyAgent(`http://localhost:${proxyPort}`)constresponse=awaitfetch(`http://localhost:${port}`,{dispatcher: agent,method: 'GET'})constdata=awaitresponse.text()console.log('Response data:',data)}catch(e){console.log(e)}})()
It is important to remark that undici does a tunneling to the proxy server using CONNECT.
Would you like to open a PR for sending a documentation update?
This would solve...
Hard to find an example of a proxy that works with undici fetch. Tried 3 different proxy servers in Node.js which all work with axios for example but not with undici fetch.
Would be very helpful to add a simple proxy server example written in Node.js to test undici fetch with.
The implementation should look like...
A small code block in the README.md like the following
Simple proxy in Node.js to test undici fetch with:
Additional context
I want to migrate from axios to fetch (Windows 11, Node.js version 20.17.0) but i've tried 3 different proxies which all work (passing through the proxy and getting a response) with axios (or postman) but none with undici (version 6.19.8) fetch. Request to proxy1.js and proxy2.js never resolves or rejects while request to proxy3.js bypasses proxy completely and gets a response.
Undici fetch test where proxy runs on http://127.0.0.1:8000 and http://127.0.0.1:4003/api/a1 is an endpoint in mockoon which returns a simple json response.
proxy1.js
proxy2.js
proxy3.js
Axios example which works with all 3 proxies:
The text was updated successfully, but these errors were encountered: