javascript - How can I use Y.mojito.models in middleware? -
i'm using nodejs mojito mvc framework.
do have access global variables middleware? how can use y.mojito.models in middleware?
// ./middleware/mymiddleware.js module.exports = function (req, res, next) { // how use y? //y.log('fails'); //y.mojito.models['mymodel'].fetch(function(err, data) { // next(); //}); };
i recommend not try that. express middleware, suppose quick job, async job generally, if request meant processed mojito dispatcher engine, should not try access runtime components in middleware.
that been said, there internal api (that again recommend not use) give access global y holds yui modules @ server side. this:
module.exports = function (config) { // `config.y.mojito.models['mymodel'].fetch()` available here return function (req, res, next) { next(); } }; aside that, if you're looking way share models, or expose global models, should @ mojito-models-addon, expose method.
again, config.y thing private , might change @ time.
update: in mojito there 2 types of middleware, traditional express middleware , mojito middleware, have prefixed mojito-, , these 1 should expose function receives config , returns transitional express middleware. without prefix, called per requests without preparation.
Comments
Post a Comment