node.js+express配置vue项目服务器
vue项目打包后如果放在express的服务器里运行?app.jsvar express = require('express');var fs = require('fs');var path = require('path');var bodyParser = require('body-parser');var app = express();app.use(bodyParser....
·
vue项目打包后如果放在express的服务器里运行?
app.js
var express = require('express');
var fs = require('fs');
var path = require('path');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// 访问静态资源
app.use(express.static(path.resolve(__dirname, '../dist')));
// 访问单页
app.get('*', function (req, res) {
var html = fs.readFileSync(path.resolve(__dirname, '../dist/index.html'), 'utf-8');
res.send(html);
});
// 监听
app.listen(8081, function () {
console.log('success listen...8081');
});
详细步骤更多推荐
已为社区贡献6条内容
所有评论(0)