25

How can I set options in the fetch method of react-native to make a call to a webserver go through a proxy.

Currently I am using axios but this doesn't work.

After adding a host header to the fetch, I can make a request through charles-proxy but it doesn't work with squid. (Error: invalid url).

serv-inc
  • 35,772
  • 9
  • 166
  • 188
Felix Bäder
  • 357
  • 3
  • 13
  • 2
    Have you found a solution? – Sérgio Reis Jun 09 '17 at 11:25
  • 2
    What are you trying to accomplish? Debugging, anonymizing requests? Have you been able to trace the requests by switching your app to debug mode (with Chrome dev tools)? – Benjamin Toueg Jun 13 '17 at 16:52
  • 1
    I think we need more detail. What are you trying to accomplish? How are you using charles? How are you using squid? – klvs Jun 16 '17 at 07:12
  • 1
    Sorry, away from the office for a little longer due to non-related issues, can't actually test it untill next week, meanwhile i'll get in touch with the rest of the developers team to see if they managed to get something. Thanks in advance – Sérgio Reis Jun 16 '17 at 12:52
  • Hi, did you figure something out with regards to this? :) – oPolo Oct 27 '18 at 10:48
  • Any solution found? I want to add proxy options in fetch – Asha Sep 17 '19 at 11:10
  • @SérgioReis Hey, how did you manage to solve it? Any help would be really appreciated. – Rishabh Bhatia Apr 03 '20 at 11:45

4 Answers4

0

Inside your package.json file that exists in your react project you can create a proxy like the following:

 "proxy": "http://localhost:5000"
Tanner
  • 720
  • 1
  • 8
  • 17
0

You can solve this by installing local-cors-proxy globally and run it by

npm install -g local-cors-proxy

Start Proxy:

lcp --proxyUrl https://www.yourdomain.ie

Then in your client code, new API endpoint:

http://localhost:8010/proxy/movies/list

Package: https://www.npmjs.com/package/local-cors-proxy

Jijo Bose
  • 318
  • 1
  • 7
  • 16
0

You can use

npm i free-proxy

package for creating proxy fetch request

Thanks

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 14 '23 at 20:03
-3

Hello You can use this module node-fetch(https://github.com/bitinn/node-fetch) and set agent param for proxy,

For more details, you can also check this https://github.com/bitinn/node-fetch/issues/79

Nisarg Thakkar
  • 1,497
  • 16
  • 25