node.js - npm build build vue via express build,但是 index.html 不起作用
问题描述
前端/config/index.js
build: {
index: path.resolve(__dirname, '../../backend/public/index.html'),
assetsRoot: path.resolve(__dirname, '../../backend/public'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
}
后端/app.js
...
app.use(require('connect-history-api-fallback')());
...
app.use('/', root);
后端/路由/root.js
const express = require('express');
const path = require('path');
const router = express.Router();
router.get('/', (req, res, next) =>{
res.sendFile(path.join(__dirname, '../public/index.html'))
});
module.exports = router;
我通过 npm run build 在后端创建了一个公共文件夹。
我通过 node app.js 运行 express 服务器,但我无法访问 index.html 和任何 vue 组件。
当与 localhost: // 3000 连接时,我得到Cannot GET /
的不是 index.html。
我怎么了?
解决方案
推荐阅读
- r - 如何用 igraph 计算最大瓶颈路径?
- r - Why manual autocorrelation does not match acf() results?
- c# - 启用将警告视为每个文件的错误
- xpath - Scrapy:以字符串和/或整数形式获取 HTML 类?
- bash - 如何使用目录中的文件前缀动态定义路径?
- java - 出现错误 - 没有符合条件的 bean 类型
- javascript - 如何在 Puppeteer 中找到 document.activeElement
- java - 偶尔而不是强制验证 Json(Entity)
- angular - 未聚焦时的样式输入下划线
- java - Listview 仅显示数组列表中的第一个结果