如何在package.json中为POST请求设置代理?
问题描述:
我有一个节点应用程序和一个嵌套在里面的create-react-app。在开发环境中,我同时运行两个服务器,一个用于快速方面,一个是反应方。如何在package.json中为POST请求设置代理?
localhost:5000
为节点/快递侧 localhost:3000
的阵营侧
在那一刻,我有一个注册http://localhost:3000/signup
页面,当用户按下“注册”按钮,它使一个POST请求到/signup
。
我想它,以便只为/signup
POST请求被代理到localhost:5000
,而不是GET请求(这对于注册表单视图页)。
我该怎么做?
的package.json(在创建反应的-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"
}
}