当pipe道/stream传输到浏览器时,HTML文件显示为明文
我有这个快速处理程序
router.get('/', ac.allow('Admin'), function (req, res, next) { let html = path.resolve(__dirname + '/../coverage/lcov-report/index.html'); fs.createReadStream(html).pipe(res); });
问题是文件被发送到浏览器, 但它只是显示为纯文本,并没有得到渲染 …有趣的,但有道理。 有谁知道这是为什么?
您需要将Content-Type
标头设置为text/html
以告诉浏览器您的响应实际上是什么。