如何从控制器/ EJS访问应用程序? Express.js
我想从我的控制器或EJS视图访问app.routes,但应用程序var不存在。 你知道我怎样才能访问我在config / routes.js中定义的所有路由?
谢谢。
PS:我使用基于express.js的sails.js。
你可以使用request.app
:
app.get('/foo', function (request, response, next) { console.log(request.app.routes); next(); });
这是最终的解决scheme:
module.exports = { index: function (req, res) { return res.view({ layout: 'layout', title: 'Trip Analyzer', routes: req.app.routes }); } };
在Javascript中使用EJS视图:
console.log(<%- JSON.stringify(routes) %>);
谢谢!