Comments (5)
It resolved, I used https://github.com/TooTallNate/node-https-proxy-agent
fetch('https://www.google.com',{ agent:new HttpsProxyAgent('http://127.0.0.1:8580')}).then(function(res){
...
})
from node-fetch.
use https://github.com/zjael/simple-proxy-agent to support more proxy type. http、socks5.
from node-fetch.
You can pass a http.Agent
with custom proxy settings: https://github.com/bitinn/node-fetch#options
see also: #8 (comment)
from node-fetch.
It resolved, I used https://github.com/TooTallNate/node-https-proxy-agent
fetch('https://www.google.com',{ agent:new HttpsProxyAgent('http://127.0.0.1:8580')}).then(function(res){ ... })
i use typescript, and it type is incompatible
import { HttpProxyAgent } from 'http-proxy-agent';
import fetch from 'node-fetch';
fetch('', {
method: 'GET',
agent: new HttpProxyAgent('http://127.0.0.1:10809')
})
Type 'HttpProxyAgent' is not assignable to type 'Agent | ((parsedUrl: URL) => Agent) | undefined'. Property 'freeSockets' is missing in type 'HttpProxyAgent' but required in type 'Agent'.
from node-fetch.
You can use package tunnel to support node fetch with proxy.
Example Implement:
const tunnel = require('tunnel');
const fetch = require('node-fetch');
import fs from 'fs';
const configTunnel = {
ca: [fs.readFileSync(
"YOUR_CERTIFICATE_PATH"
)],
proxy: {
host: this.currentIP,
port: proxyPort,
},
};
const tunnelHTTPS = tunnel.httpsOverHttp(configTunnel);
const tunnelHTTP = tunnel.httpOverHttp(configTunnel);
let config: Record<string, any> = {
url: flow.request.url,
method: method,
headers: headers,
agent: flow.isSSL ? tunnelHTTPS : tunnelHTTP,
};
if (flow.request.bodySize > 0 && method !== 'GET' && method !== 'HEAD') {
config.body = flow.request.body;
}
try {
const response = await fetch(flow.request.url, config);
} catch (e: any) {
throw new Error(e.message);
}
Note that: node fetch with proxy doesn't work if Method GET contains body.
from node-fetch.
Related Issues (20)
- `node-fetch` does not work behind a proxy HOT 6
- Suggest: Align fetch function's type with the latest Typescript type on fetch function?
- node v20, closing server and re-listening between requests causes ECONNRESET HOT 3
- SSL error when setting host: header correctly HOT 1
- Node-fetch allows setting forbidden headers HOT 3
- Could not catch Premature close error HOT 1
- Broken clone() method in newer version of 3.3.* (at least)
- Critical dependency:
- failing without clear reason HOT 3
- FormData with invalid Content-Length HOT 2
- Pure ems bundle prevents node-fetch usage in libraries/frameworks HOT 2
- Can't import HOT 1
- v2.7.0: punycode is deprecated in 'whatwg-url' and 'tr46' HOT 3
- Faulty NPM upload 2.7.0 HOT 3
- The 'body' stream never ends for empty HTTP response bodies on Node 16 HOT 1
- Unhandled 'error' event when using AbortSignal to cancel requests HOT 2
- Andoka now
- bug issue
- Error [ERR_REQUIRE_ESM]: require() of ES Module
- Error [ERR_REQUIRE_ESM]: require() of ES Module HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-fetch.