【发布时间】:2014-05-23 07:50:24
【问题描述】:
我有this node.js 项目,它使用玉模板。但我需要使用简单的 html 页面。安全转化所需的指南。
我需要使用完整的 .html 页面,例如 index.html、login.html。没有任何模板引擎显示在 localhost:3000 和 localhost:3000/login.html 等路由上。应该可以使用全部功能。
【问题讨论】:
标签: node.js express template-engine
我有this node.js 项目,它使用玉模板。但我需要使用简单的 html 页面。安全转化所需的指南。
我需要使用完整的 .html 页面,例如 index.html、login.html。没有任何模板引擎显示在 localhost:3000 和 localhost:3000/login.html 等路由上。应该可以使用全部功能。
【问题讨论】:
标签: node.js express template-engine
你可以在config/express.js改:
app.set('view engine', 'jade')
例如,如果您想使用Handlebars,则在packages.json 中删除"jade": "latest", 并添加"handlebars": "latest"。然后运行npm install 并编辑config/express.js:
app.set('view engine', 'handlebars')
【讨论】:
默认表达服务器静态html文件。
将您的 html 文件放在 /public 文件夹中:
...
/public
index.html
login.html
...
然后去 localhost:3000/ 或 localhost:3000/login.html 但这是静态文件,然后应用程序逻辑应该在前端。例如使用角度或主干。
【讨论】:
app.get('/any_location', function(req, res){
res.sendFile('Location_to_htmlFile');
})
【讨论】: