Configuration for user-provided middlewares #661

wants to merge 2 commits into from

2 participants


Now the developer can load custom middlewares from a folder. If options.midDir is empty, the folder ./middleware is assumed to be the default location to store custom middlewares. This new configuration is useful for middlewares that need to be loaded before the server starts.

Example of configuration:


options.midDir = 'middleware';
// options.midDir = './custom-scripts/middleware'; works too

// Some middlewares
options.appConfig = {
middleware: [

var app = Mojito.createServer(options);



The change you are proposing is not backwards compatible.

It seems that the following behaviour needs to be documented better:

if you use 'middleware/passport-init' instead of 'middleware-passport-init', you can specify any subfolder transparently and mojito will handle it correctly.

Also, if you name one of your middleware files beginning with mojito, e.g. 'middleware/mojito-my-Y-enabled-script' you will disable the default mojito middleware and your script will be passed a config object.

2c Ron


it's just another way to set up where to load middlewares. If options.midDir was not specified, mojito will assume the folder 'middleware' as default. But you can still set up application.json.


@ooskapenaar hmm... It would be better to let application.json handle all of this.

@rodnic rodnic closed this Jan 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment