Shi*_*Cat 2 heroku express reactjs
当我重新加载 Heroku 页面时,出现内部服务器错误,状态代码为 500。
但在我的本地环境中并没有发生这种情况。
最重要的是,
当我访问正确重定向并正常显示的路由地址时。
当我重新加载页面时,在 chrom dev 工具的网络信息中表示该页面没有处理任何进程。
我的程序有什么问题?这是网站。
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
Run Code Online (Sandbox Code Playgroud)
服务器代码
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...");
}
Run Code Online (Sandbox Code Playgroud)
前端
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>
);
}
Run Code Online (Sandbox Code Playgroud)
小智 5
我也遇到了类似的问题;在本地工作,而不是在 Heroku 上工作。对我来说,修复方法是:
const path = require("path");到我的 server.js 文件中。添加此后,它似乎对我有用。
您还可以检查 Heroku 日志,了解有关服务器错误的更多详细信息,方法是转到您的 Heroku 帐户并单击应用程序,然后单击导航栏中的按钮并选择“查看日志”
| 归档时间: |
|
| 查看次数: |
1023 次 |
| 最近记录: |