首页 文章

代理在 create-react-app 和 axios 中不起作用

提问于
浏览
1

我在 package.json 中添加了"proxy": "http://localhost:3001",然后运行 npm run start 来启动客户端应用程序。

然后我用 axios 做这件事

axios.get('/')
    .then(resp => {
      console.log(resp)
      this.setState({
        name: resp.name
      })
    })

我打开网络选项卡我看到它调用http://localhost:3000而不是代理,任何线索?我有一台运行在 3001 上的快速服务器。

1 回答

  • 2

    打开网络选项卡我看到它调用http://localhost:3000而不是代理

    这就是代理的工作方式!浏览器向您运行代理服务器的localhost:3000发出请求,该请求将请求转发给localhost:3001

相关问题