首页 > 解决方案 > Node/Express serving react app : Get request error 304 Not modified

问题描述

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

标签: node.jsreactjsexpresspassport-localhttp-status-code-304

解决方案


推荐阅读