小编sid*_*oot的帖子

React Native fetch a local server using a proxy

In my react native app I am trying to perform a fetch to my local backend server. In my package.json I have put "proxy": "http://localhost:3000" .

My fetch looks like

fetch('/')
  .then(response => response.json())
  .then(json => console.log(json))
  .catch(err => console.log)
Run Code Online (Sandbox Code Playgroud)

It catches an error

[TypeError: Network request failed]
Run Code Online (Sandbox Code Playgroud)

When I remove the proxy and manually enter the address in the fetch it works and my server receives a GET request.

fetch('http://localhost:3000')
  .then(response => response.json())
  .then(json => console.log(json))
  .catch(err => console.log)
Run Code Online (Sandbox Code Playgroud)

api proxy fetch reactjs react-native

5
推荐指数
1
解决办法
199
查看次数

标签 统计

api ×1

fetch ×1

proxy ×1

react-native ×1

reactjs ×1