我有简单的server.js文件,如下所示:快速路由的单页的应用程序似乎并没有工作
const express = require('express');
const app = express();
app.set('port', (process.env.PORT || 3031));
if (process.env.NODE_ENV === 'production') {
app.use(express.static('build'));
app.get('*', (req, res) => {
res.sendFile('build/index.html');
})
}
app.listen(app.get('port'), (error) => {
if (error) return console.error(error.message);
console.log(`Server started at: http://localhost:${app.get('port')}/`);
})
我希望它重新路由的所有路径,以在生产index.html,然后启动服务器。目前路由位似乎行不通,因为我收到以下错误:
Server started at: http://localhost:3031/ TypeError: path must be absolute or specify root to res.sendFile
重复:https://stackoverflow.com/questions/25463423/res-sendfile-absolute-path –