Skip to content

Using kraken js middleware config to setup environment specific routes

Poornima Venkat edited this page Apr 7, 2015 · 8 revisions

Using kraken-js middleware config to setup environment specific routes

  • Defining a factory that returns a router
//in path/to/controller
var express = require('express');

module.exports = function() {
  var router = express.Router();

  // path in `require`s below will be relative to this file
  router.get('/login', require('./path/to/loginMiddleware'));
  router.post('/login', require('./path/to/loginPostMiddleware'));
  router.get('/some/other/route', require('./path/to/otherRouteMiddleware'));

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