我在 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 回答
这就是代理的工作方式!浏览器向您运行代理服务器的
localhost:3000
发出请求,该请求将请求转发给localhost:3001