0

I'm making an application with expressjs as backend and reactjs as frontend. During the development I used proxy in package.json for sending and receiving requests. And now I'm about to deploly the application on heroku by serving react build folder in express. The problem is not that expressjs is not serving my app , the problem is when I send request from frontend to backend for signin via passport-local, It works perfectly, but the second request that I'm sending, I'm getting the response 304 not modified.

I don't understand why is this happening. Following is the code. of my fetch request from reactjs.

    fetch('/user/signin', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(data),
        })
            .then((res) => res.json())
            .then((resp) => {
                if (resp.success) {
                    dispatch({ type: 'SIGN_IN_SUCCESS' });
                    dispatch({ type: 'GET_USER_PROCESS' });
                    fetch('/user/get_user')
                        .then((res) => res.json())
                        .then((resp) => {
                            if (resp.success) {
                                dispatch({ type: 'GET_USER_SUCCESS', payload: resp.user });
                                if (resp.user.role.toLowerCase() === 'admin') {
                                    history.push('/admin/users');
                                } else {
                                    history.push('/user/dashboard');
                                }
                            } else {
                                dispatch({ type: 'GET_USER_FAILURE' });
                            }
                        });
                } else {
                    if (resp.unauthorized) {
                        message.error('Check your email and password.');
                    } else {
                        message.error('There was some error.');
                    }
                    dispatch({ type: 'SIGN_IN_FAILURE' });
                }
            });

The first request goes perfectly but the second response that i see in network section is 304 not modified.

Any solution or recommendation for this ? THanks in advance

  • 304 doesn't mean an error, it means the same data is received again. – aRvi Sep 12 '20 at 06:18
  • ok i got it but in my application I'm sending this request on every refresh to get the user and store it in my redux store. Can you tell me how I can like bypass that. I just don't understand how my application will run if at every request I get this response. – MoeezShahid Sep 12 '20 at 06:24

0 Answers0