matthew-andrews / isomorphic-fetch

Isomorphic WHATWG Fetch API, for Node & Browserify
MIT License
6.95k stars 289 forks source link

proxy for isomorphic-fetch #171

Open steeply opened 6 years ago

steeply commented 6 years ago

Prompt how to use isomorphic-fetch together with a proxy?


import fetch from 'isomorphic-fetch';

options = {
      method,
      timeout,
      headers: {
        'Cache-Control': 'no-cache',
        'Content-Type': 'application/json; charset=utf-8',
        'proxy': ?????
      },
      body: JSON.stringify(data)
    };
return fetch(url, options)
mdogadailo commented 6 years ago

I think you can't use proxy with client implementation. But for server version:

import fetch from 'isomorphic-fetch';
import proxyAgent from 'http-proxy-agent';
//import proxyAgent from 'https-proxy-agent'; // HTTPS

const options = {
    method: 'GET',
    agent: new proxyAgent('http://proxy:8080'),
    body: JSON.stringify(data)
};

fetch(url, options)
jimmywarting commented 5 years ago

did agent and http-proxy-agent solve it? can this be closed now?

pkvpraveen commented 4 years ago

It did solve for me.

import fetch from 'isomorphic-unfetch';
import HttpsProxyAgent from 'https-proxy-agent';
const res = await fetch('http://api.tvmaze.com/search/shows?q=batman', {agent: new HttpsProxyAgent('<myproxy>')});