Skip to content

Instantly share code, notes, and snippets.

@pvenkatakrishnan
Last active August 29, 2015 14:18
Show Gist options
  • Save pvenkatakrishnan/07e82da97aa43ab6397f to your computer and use it in GitHub Desktop.
Save pvenkatakrishnan/07e82da97aa43ab6397f to your computer and use it in GitHub Desktop.
Using middleware config to define environment specific routes in krakenjs apps.

Defining router middleware

//in path/to/controller
var express = require('express');
var router = express.Router();

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

module.exports = function() {
  return router;
}

Adding the middleware to your <env.json>

{
    "middleware": {
        "envRouter" : {
            "enabled" : true,
            "priority": 100 /*your appropriate priority*/,
            "module": {
                "name": "path/to/controller"
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment