渲染原始HTML [英] Render raw HTML

查看:101
本文介绍了渲染原始HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Express 3渲染原始的 .html 页面:

  server.get('/',function(req,res){
res.render('login.html');
}

这是我如何配置服务器来呈现原始HTML页面(灵感来自这个过时的问题):

  server 
.set('view options',{layout:false})
.set('views','./../')
.engine('html' function(str,options){
return function(localals){
return str;
};
});
pre>

不幸的是,使用此配置页面挂起并且永远不会正常渲染我做错了什么我如何使用Express 3渲染原始的HTLM,而不需要花哨的渲染引擎作为玉和EJS?

解决方案

如果实际上并不需要将数据注入到模板中,则表达式中最简单的解决方案是使用静态文件服务器( express.static())。

但是,如果您还想手动将路由连接到页面(例如,将/映射到login.html),可以尝试 res.sendFile()发送您的html文档:



http://expressjs.com/api.html#res.sendfile


I want to render raw .html pages using Express 3 as follows:

server.get('/', function(req, res) {
    res.render('login.html');
}

This is how I have configured the server to render raw HTML pages (inspired from this outdated question):

server
    .set('view options', {layout: false})
    .set('views', './../')
    .engine('html', function(str, options) {
        return function(locals) {
             return str;
        };
    });

Unfortunately, with this configuration the page hangs and is never rendered properly. What have I done wrong? How can I render raw HTLM using Express 3 without fancy rendering engines such as Jade and EJS?

解决方案

If you don't actually need to inject data into templates, the simplest solution in express is to use the static file server (express.static()).

However, if you still want to wire up the routes to the pages manually (eg your example mapping '/' to 'login.html'), you might try res.sendFile() to send your html docs over:

http://expressjs.com/api.html#res.sendfile

这篇关于渲染原始HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆