我有一个节点应用程序和一个嵌套在其中的create-react-app。在开发环境中,我同时使用两个服务器,一个用于快速端,另一个用于响应端。
localhost:5000
表示节点/快速方面
反应方localhost:3000
目前,我有一个注册页面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"
}
}