【发布时间】:2020-03-04 12:39:49
【问题描述】:
我想为我的静态文件设置路由:
// server.js
app.use('/', require('./routes/ui/templates'));
问题是我无法从 html->xhtml 更改内容类型。这是我的路线:
const express = require('express');
const router = express.Router();
// Path configs
const pathRoot = __dirname
const pathPublic = pathRoot + "/../../public/"
router.use('/', express.static(pathPublic));
router.get('/', (req, res) => {
console.log(pathPublic)
res.sendFile('index.html', {root: pathRoot});
})
router.use((req, res, next) => {
res.type('application/xhtml+xml');
next();
})
module.exports = router;
请注意,由于某种原因,如果我不添加 router.use(...)
我的索引文件根本没有提供。据我了解,我拥有的中间件
写的应该是最后一个,因为我试图捕获响应并修改它。
如果我错了,请纠正我。
【问题讨论】:
标签: express