“ejs.render”正在呼叫下一个路线
当我在http:// localhost / client中input时,显示404。
app.get('/client', function(req, res) { ... ejs.render('any template', {}); ... res.end(); }); app.get('*', function(req, res) { console.log('404'); ... });
但如果我删除“ejs.render”并把res.end('任何html')的作品。 我如何使用“ejs.render”而不是调用404? 谢谢。 这是一个错误。
你需要设置ejs
使用快递使用EJS。 Express应用程序生成器使用Jade作为默认值,但它也支持其他几种(如ejs
, ejs
等)。
例如:
var express = require('express'); var app = express(); // set the view engine to ejs app.set('view engine', 'ejs'); // use res.render to load up an ejs view file // index page app.get('/client', function(req, res) { res.render('pages/index'); //does not needs ejs extension }); app.get('*', function(req, res){ res.send('what???', 404); }); app.listen(8080); console.log('8080 is the magic port');
当您向主页发出请求时,index.ejs文件将呈现为HTML
。
见这里的官方文档。
- NodeJS Express app.locals不能直接在函数中访问
- 使用PassportJSvalidationAndroid应用程序
- Express.js ..通常的后端/托pipe是什么?
- 为什么Angular Universal中的res.render花了这么长时间?
- 如何在Express中使用basic-auth中间件指向默认login页面
- 我需要创buildurl来获取哪个接受数组,如何在node.js /从请求中提取数组?
- 快递js 4 – 如何configuration没有app.configure?
- NodeJS(Express 4)+ i18n +下划线:问题与模板中的翻译
- 如何将socket.io与webpack-hot-middleware一起使用?