Created
April 10, 2015 17:08
-
-
Save jincod/16c7bec5d8c44431a142 to your computer and use it in GitHub Desktop.
express.js route builder from controllers
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
fs = require 'fs' | |
path = require 'path' | |
routes = fs.readdirSync('./server/controllers').map (f) -> | |
path.basename(f, path.extname(f)) | |
addRouter = (app, name) -> | |
name = name.replace 'index', '' | |
app.use '/' + name, require './controllers/' + name | |
module.exports = (app) -> | |
for route in routes | |
addRouter app, route |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment