应用程序在开发模式下运行正常,但是,在使用构建模式时,我遇到了一个问题。使用Express server.js文件,该应用甚至无法通过在本地测试我的server.js文件来呈现。
下面是我的server.js文件的两个类似版本,它们都无法正常工作,并且都记录了相同的错误,我还在下面附有屏幕截图
// version one
const express = require('express');
const port = process.env.PORT || 5000;
let app = express();
app.use(express.static(__dirname + "/dist/"));
app.get(/.*/, (req, res) => {
res.sendfile(__dirname + '/dist/index.html'); //path to index.html
});
app.listen(port, () => {
console.log('Listening on port ' + port)
});
//version two
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.vue文件