Skip to content

Using kraken js middleware config to setup environment specific routes

Matt Edelman edited this page Apr 13, 2015 · 8 revisions
  • Define a module that exports a function 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;
}
  • Include the router module in <env>.json's middleware section
{
    "middleware": {
        "envRouter" : {
            "enabled" : true,
            "priority": 100 /*your appropriate priority*/,
            "module": {
                "name": "path:./path/to/controller"
            }
        }
    }
}