Created
April 25, 2016 08:22
-
-
Save marcusradell/09b27346712ecec94146a942264b22a5 to your computer and use it in GitHub Desktop.
Componentized Express router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create() { | |
var router = routerFactory.create() | |
router.get('/', onGetItems) | |
router.get('/verified', onGetVerifiedItems) | |
router.get('/status', onGetStatusList) | |
return { | |
router: router | |
} | |
} | |
module.exports = { | |
create | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const subrouterInits = [ | |
{ | |
path: '/foo', | |
create: require('../components/foo/router').create | |
} | |
] | |
function create() { | |
var router = routerFactory.createRouter(); | |
subrouterInits.forEach(function onForEach(subRouterCreate) { | |
var subrouter = subRouterCreate(); | |
router.use(subRouterCreate.path, subrouter.router); | |
}); | |
return { | |
router | |
}; | |
} | |
module.exports = { | |
create | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
function create() { | |
return express.Router() | |
} | |
module.exports = { | |
create | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment