Skip to content

Instantly share code, notes, and snippets.

@sandfox
Created February 19, 2014 23:57
Show Gist options
  • Save sandfox/9104144 to your computer and use it in GitHub Desktop.
Save sandfox/9104144 to your computer and use it in GitHub Desktop.
too simple express/restify/whatever controller + routemap example
var express = require('express');
var blahController = require('./example-controller'); //and so on and so forth
var routes = require('./routes');
var app = express()
var controllers = {
blah: blahController,
user: userController
}
routes(app, controllers)
app.listen(8045)
module.exports= {
list: function(req, res, next){
//some logic or whatevre
},
remove: function(req, res, next){
//some other logic
}
}
authMagic = require('jwt') //or whatever, or inject it with the app and controllers
module.exports = function(app, controllers){
app.get('/v1/users', authMagic, controllers.users.list);
app.del('/v1/tings/:id', authMagic, controllers.tings.remove);
app.put('/v1/stores/:id', authMagic, controllers.users.list);
app.get('/v1', controllers.home);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment