bradtraversy / mern_shopping_list

Shopping List built with MERN and Redux
605 stars 436 forks source link

Getting 404 (Not found) error using axios in a redux action creator, to make api calls to an expressJs backend #32

Open williamdarkocode opened 4 years ago

williamdarkocode commented 4 years ago

The file system, front-end, and back-end architecture are modeled after this project, but action creators are returning 404s.

Example 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
    });
})

} `