Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Allow user-provided middlewares with a name starting with 'mojito-' t…
Browse files Browse the repository at this point in the history
…o gain access to the resource store, YUI instance, logger, context, etc.
  • Loading branch information
jlecomte authored and Isao Yagi committed Jun 13, 2012
1 parent 73eed95 commit ac4977e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions source/lib/index.js
Expand Up @@ -111,6 +111,7 @@ MojitoServer.prototype = {
middleware,
m,
midName,
midBase,
midPath,
midFactory,
hasMojito,
Expand Down Expand Up @@ -294,7 +295,7 @@ MojitoServer.prototype = {
// We assume the middleware is a factory function
// and pass in the following config object when
// calling said function.
//
//
// midConfig = {
// Y: Y,
// store: store,
Expand All @@ -308,7 +309,16 @@ MojitoServer.prototype = {
// specified by path
midPath = libpath.join(options.dir, midName);
//console.log("======== MIDDLEWARE user " + midPath);
app.use(require(midPath));
midBase = libpath.basename(midPath);
if (0 === midBase.indexOf('mojito-')) {
// Same as above (case of Mojito's special middlewares)
// Gives a user-provided middleware access to the YUI
// instance, resource store, logger, context, etc.
midFactory = require(midPath);
app.use(midFactory(midConfig));
} else {
app.use(require(midPath));
}
}
}

Expand Down

0 comments on commit ac4977e

Please sign in to comment.