Return raw html with node (just html into a var)

Return raw html with node (just html into a var)

我正在尝试通过节点使用 jade,但是当我 运行 这段代码时,我得到了由 jade beetwen 'pre' 标签解析的 html。

var http = require('http');
var jade = require('jade');

http.createServer(function(request, response){
    response.writeHead(200, {'Content-Type': 'text/plain'});

    response.end(jade.renderFile('index.jade'));
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

如何使节点渲染为原始 html 而不转义任何内容?

要渲染 HTML,您需要使用 'Content-Type': 'text/html; charset=UTF-8'。使用 text/plain 会将 HTML 呈现为纯文本(无解释),并且看起来 HTML 是在 <pre></pre> 标签之间呈现的。