Skip to content

Using krakenjs middleware config for express subapps mounting

Poornima Venkat edited this page Apr 7, 2015 · 8 revisions
  • Defining a factory that returns a router
//in 'subapp' module's index.js
var express = require('express');
var jade = require('jade');

module.exports = function() {
  var app = express();

  //setup anything app specific

   // view engine
   app.set('view engine', 'jade');

   // view paths - relative to the module's path
   app.set('views', './views')

   // routes

   app.get('/login', require('./path/to/loginMiddleware'));
   app.post('/login', require('./path/to/loginPostMiddleware'));
   app.get('/some/other/route', require('./path/to/otherRouteMiddleware'));

   return app;
}
  • Including the factory on your middleware config in <env>.json
{
    "middleware": {
        "subapp" : {
            "enabled" : true,
            "priority": 100 /*your appropriate priority*/,
            "module": {
                "name": "subapp"
            }
        }
    }
}