gpt4 book ai didi

javascript - 返回带有 Node 的原始 html(只是 html 到 var 中)

转载 作者:行者123 更新时间:2023-12-03 08:21:10 25 4
gpt4 key购买 nike

我试图通过 Node 使用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/');

如何使 Node 渲染原始 html 而不进行任何缩放?

最佳答案

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

关于javascript - 返回带有 Node 的原始 html(只是 html 到 var 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33742151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com