我有一个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)
});
答案 0 :(得分:0)
你失踪了
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)
});