Render raw HTML

前端 未结 11 1185
自闭症患者
自闭症患者 2020-12-23 18:48

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

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

11条回答
  •  星月不相逢
    2020-12-23 19:18

    as the document says : 'Express expects: (path, options, callback)' format function in app.engin(...).

    so you can write your code like below(for simplicity, but it work):

    server
    .set('view options', {layout: false})
    .set('views', './../')
    .engine('html', function(path, options, cb) {
        fs.readFile(path, 'utf-8', cb);
    });
    

    of course just like 2# & 3# said, you should use express.static() for static file transfer; and the code above not suit for production

提交回复
热议问题