node.js - 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
解决方案
推荐阅读
- java - 按属性分组对象列表并将其他剩余属性设置为不同的对象列表:Java 8 流和 Lambda
- google-apps-script - 在谷歌脚本中,强制工作表和新表单相互同步
- javascript - 用户的背景图像和重置按钮
- xml - 从 CSV 文件添加 XML 属性
- android - 可重现:升级 Gradle icm Android8.0 后 -- 无法重新安装 App - 错误 INSTALL_FAILED_NO_MATCHING_ABIS (Binder.java:682/674)
- angular - 如何测试不应导出的功能?
- nhibernate - NHibernate 使用 sys.sequences 将新 id 插入数据库的步骤
- datetime - 在不使用静态对象的情况下在 groovy 中严格解析日期时间
- c++ - 推断大多数模板对象的参数,但在调用模板函数时与其他对象显式?
- php - PHP 卷码 400 [API]