Skip to content

Instantly share code, notes, and snippets.

@indiejoseph
Created March 18, 2014 14:56
Show Gist options
  • Save indiejoseph/9621725 to your computer and use it in GitHub Desktop.
Save indiejoseph/9621725 to your computer and use it in GitHub Desktop.
Express 4.x Router index.coffee
fs = require 'fs'
path = require 'path'
router = (require 'express').Router()
role = require './role'
# acl
router.use '/admin*', role.isAuthorized()
# load all routers in current folder
fs
.readdirSync(__dirname)
.filter( (file) ->
return (file.indexOf('.') isnt 0) && (file isnt 'index.coffee')
)
.forEach( (file) ->
router.use('/admin', (require path.join(__dirname, file)))
)
module.exports = router
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment