【发布时间】:2018-01-28 00:51:01
【问题描述】:
我有一个节点应用程序和一个嵌套在其中的 create-react-app。在开发环境中,我使用并发运行两台服务器,一台用于 express 端,一台用于 react 端。
localhost:5000 用于节点/快递端
localhost:3000 用于 React 端
目前,我有一个注册页面 http://localhost:3000/signup,当用户按下“注册”按钮时,它会向 /signup 发出 POST 请求。
我希望仅将 /signup 的 POST 请求代理到 localhost:5000 而不是 GET 请求(这是注册表单的查看页面)。
我该怎么做?
package.json(在 create-react-app 中):
{
"name": "client",
"version": "0.1.0",
"private": true,
"proxy": {
"/signup": {
"target": "http://localhost:5000"
}
},
"dependencies": {
"axios": "^0.16.2",
"lodash": "^4.17.4",
"materialize-css": "^0.100.2",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-redux": "^5.0.6",
"react-router-dom": "^4.2.2",
"react-scripts": "1.0.14",
"redux": "^3.7.2",
"redux-form": "^7.0.4",
"redux-thunk": "^2.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
【问题讨论】:
标签: node.js post proxy package.json