通过管道/流式传输到浏览器时,HTML文件显示为纯文本

通过管道/流式传输到浏览器时,HTML文件显示为纯文本,html,node.js,express,web,browser,Html,Node.js,Express,Web,Browser,我有个快递员 router.get('/', ac.allow('Admin'), function (req, res, next) { let html = path.resolve(__dirname + '/../coverage/lcov-report/index.html'); fs.createReadStream(html).pipe(res); }); 问题是,文件被发送到浏览器,但它只是以纯文本的形式出现,不会被渲染…有点滑稽,但很有意义。有人知道这是为什么吗

我有个快递员

router.get('/', ac.allow('Admin'), function (req, res, next) {

  let html = path.resolve(__dirname + '/../coverage/lcov-report/index.html');

  fs.createReadStream(html).pipe(res);

});

问题是,文件被发送到浏览器,但它只是以纯文本的形式出现,不会被渲染…有点滑稽,但很有意义。有人知道这是为什么吗?

您需要将
内容类型
标题设置为
文本/html
,告诉浏览器您的实际响应是什么。

我一直过度依赖express为我设置这些标题