1
我有一個節點應用程序和一個嵌套在裏面的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"
}
}
休息的代碼:https://github.com/drhectapus/Voting-App