The React-Redux front end production server is running on port 3000 (localhost:3000). The node-expressjs server is running on port 5000 (localhost:5000); I've placed a "proxy" value in the client side package.json, and even tried a proxy value in the options field of the axios call. However, axios always ignores the proxy values, and uses the client-side production build server, to make the api call to the express backend which sensibly returns a 404 error.
client-side package.json
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"mongoose": "^5.7.12",
"react": "^16.8.6",
"react-addons-css-transition-group": "^15.6.2",
"react-dom": "^16.8.6",
"react-redux": "^7.1.0",
"react-router": "^5.0.1",
"react-router-dom": "^5.1.2",
"react-router-redux": "^4.0.8",
"react-scripts": "3.0.1",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"proxy": "http://localhost:5000",
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"concurrently": "^4.1.1"
}
}
The action creator:
export const registerUser = (SignUpFormData) => dispatch => {
const configs = {
headers: {
'Content-Type': 'application/json'
},
proxy: {
host: "http://localhost:5000",
port: 5000
}
};
const requestBody = JSON.stringify({...SignUpFormData});
axios.post('/api/users/register', requestBody, configs)
.then(res => {
dispatch({
type: UserActions.USER_AWAITING_EMAIL_VERIFICATION,
userInfo: res.data.userName,
msg: res.data.msg,
})
})
.catch(error => {
dispatch(returnAuthErros(error.response.data.msg, error.response.status, 'USER_SIGNUP_FALIURE'));
dispatch({
type: UserActions.USER_SIGNUP_FALIURE,
msg: error.response.data.msg
});
})
}
If any one can let me know if I'm actually tackling the problem, but my efforts just aren't fruitful, or I'm completely missing the point here. Cheers.