返回带有node的原始html(只将html放入var中)

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

本文关键字:html 放入 只将 var 返回 node 原始      更新时间:2023-09-26

我试图通过node使用jade,但当我运行此代码时,我得到了由jade beetween'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而不进行任何scaping?

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