node.js - 部署在 Heroku 上时,令牌未保存在本地存储中
问题描述
我构建了一个在本地机器上运行良好的 MERN 应用程序。但是当我将它部署到 Heroku 时,它无法请求 api 并返回 400 Bad Request。它有一个注册/登录,当我输入详细信息时我注意到它没有将令牌保存在本地存储中。因此它无法访问私有路由 APIS。但是,本地存储是前端的一部分,那么为什么它在 Heroku 中的行为不同呢?
这是一个请求:
fetch("/api/auth", {
method: "POST",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify(data),
})
.then((res) => res.json())
.then((data) => {
if (data.token) {
localStorage.setItem("token", data.token);
setAuthStatus(true);
}
})
.catch((err) => console.log(err));
我有这个作为代理:
"proxy": "http://localhost:5000"
解决方案
推荐阅读
- javascript - useEffect 中的滚动事件不会重新初始化
- javascript - 关闭传单中的弹出窗口
- python-3.x - Python,Selenium 找不到基于 xpath 的输入字段
- ios - 关于状态更改问题的 SwiftUI 刷新列表
- javascript - 如何使用 JavaScript 分块上传视频并将视频保存在 express 中?
- java - @Configuration 类,将@Bean 传递给其他@Bean
- linux - 需要找到一个大小超过 1GB 且文件类型为扩展名的文件
- c# - C# Windows Service Import C++ dll Crash with Event ID: 1000 clr.dll
- postgresql-9.5 - 无法从另一个 jsonb 列添加到 json 值
- python - 错误:无法将大小为 65536 的数组重新整形为形状 (2,227)