我有一个Vue CLI3应用程序设置,当我使用npm run serve
运行应用程序时,它工作得很好,但是,在运行npm run build
准备部署应用程序后,当使用Express运行应用程序时,它在控制台中给出了一个错误,说cannot set property render of undefined
。这是我的应用程序根目录中的server.js文件设置
const express = require('express');
const path = require('path');
const serveStatic = require('serve-static');
let app = express();
app.use(serveStatic(__dirname + "/dist"));
const port = process.env.PORT || 5000;
app.get('*', (req, res) => {
res.sendFile(path.join( __dirname, './dist/index.html')); //path to index.html
});
app.listen(port, () => {
console.log('Listening on port ' + port)
});
你错过了
app.get('*', function(req, res) {
res.sendFile(path.join( __dirname, './index.html')); //path to index.html
});
你的新代码就像
const express = require('express');
const path = require('path');
const serveStatic = require('serve-static');
let app = express();
app.use(serveStatic(__dirname + "/dist"));
const port = process.env.PORT || 5000;
app.get('*', function(req, res) {
res.sendFile(path.join( __dirname, './index.html')); //path to index.html
});
app.listen(port, () => {
console.log('Listening on port ' + port)
});