isomorphic-fetch icon indicating copy to clipboard operation
isomorphic-fetch copied to clipboard

proxy for isomorphic-fetch

Open steeply opened this issue 6 years ago • 3 comments

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)

steeply avatar Jul 08 '18 10:07 steeply

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)

mdogadailo avatar Oct 05 '18 08:10 mdogadailo

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

jimmywarting avatar Jan 25 '19 16:01 jimmywarting

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>')});

pkvpraveen avatar Jan 14 '20 08:01 pkvpraveen