Skip to content
Browse files

Allow user-provided middlewares with a name starting with 'mojito-' t…

…o gain access to the resource store, YUI instance, logger, context, etc.
  • Loading branch information...
1 parent 73eed95 commit ac4977ece88a43b8f66a232e3b660665d55fa3ab @jlecomte jlecomte committed with
Showing with 12 additions and 2 deletions.
  1. +12 −2 source/lib/index.js
View
14 source/lib/index.js
@@ -111,6 +111,7 @@ MojitoServer.prototype = {
middleware,
m,
midName,
+ midBase,
midPath,
midFactory,
hasMojito,
@@ -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,
@@ -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));
+ }
}
}

0 comments on commit ac4977e

Please sign in to comment.
Something went wrong with that request. Please try again.