reactjs - Mern heroku 重新加载页面时出现内部服务器错误
问题描述
当我重新加载 Heroku 页面时,我收到一个内部服务器错误,状态码为 500。
但它不会在我的本地环境中发生。
最重要的是,
当我访问正确重定向并正常显示的路由地址时。
当我重新加载页面时,在 chrom 开发工具的网络信息中说该页面没有处理任何进程。
我的程序有什么问题?这是网站。
https://boiling-falls-61617.herokuapp.com/
这是我的错误和代码。
错误
2020-03-15T19:33:53.875586+00:00 heroku[router]: at=info method=GET path="/dashboards/5e6b999eb7f157252c8c6937" host=boiling-falls-61617.herokuapp.com request_id=785b2a93-2739-455f-856e-e59fb5af18ce fwd="99.251.226.61" dyno=web.1 connect=0ms service=2ms status=500 bytes=404 protocol=https
服务器代码
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "client", "build")));
app.get("*", (req, res) => {
// don't serve api routes to react app
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
console.log("Serving React App...");
}
前端
function App() {
return (
<MuiThemeProvider theme={theme}>
<BrowserRouter>
<PrivateRoute path='/dashboards/:dashboardId' component={DashBoard} />
<Route exact path='/' component={SignIn} />
<Route path='/signup' component={SignUp} />
<PrivateRoute
path='/(dashboards|calendar)/:dashboardId/columns/:columnId/tasks/:taskId'
render={props => <CardModal {...props} />}
/>
<Route path='/calendar/:dashboardId' component={Calendar} />
</BrowserRouter>
</MuiThemeProvider>
);
}
解决方案
我遇到了类似的问题;在本地工作,而不是在 Heroku。对我来说,解决方法是:
- 我必须明确添加
const path = require("path");
到我的 server.js 文件中。
添加后,它似乎对我有用。
您还可以查看 heroku 日志以获取有关服务器错误的更多详细信息,方法是转到您的 heroku 帐户并单击应用程序,然后单击导航栏中的按钮并选择“查看日志”
推荐阅读
- java - 如何使用 .bat 在 mac 中启动 appium 桌面 1.6.1
- azure-ad-b2c - 是否可以使用 Azure B2C 自定义策略中的声明转换来计算年龄组?
- node.js - 如果 promise 失败则停止程序
- c# - 如果用户关闭聊天,我的机器人如何注意到?
- c - 从 fortran 调用 c 函数(类型枚举)
- javascript - $onChanges 未触发
- security - 当我在 FrontOffice 中更改安全设置时,这些更改不会转到 BackOffice
- linux - 百胜回购问题
- java - 使用新字体时在 android studio 中显示渲染错误
- javascript - 将花括号中的数组转换为方括号数组