-
-
Save dotproto/16a15208871f2a54b528 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'); | |
var app = express(); | |
// Load routes | |
require('./src/routes')(app); |
This file contains hidden or 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 client = require('../db.js'); | |
modules.exports.index = function(req,res) { | |
res.render('issues/index', {issues: client.issues}); | |
} |
This file contains hidden or 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
module.exports = function(){ | |
var app = null; | |
function route(method, path, ctrlMethod) { | |
if (typeof ctrlMethod === "function") { | |
method(path, ctrlMethod); | |
} | |
} | |
function get(path, ctrlMethod) { | |
route(app.get, path, ctrlMethod); | |
} | |
function post(path, ctrlMethod){ | |
route(app.post, path, ctrlMethod); | |
} | |
function del(path, ctrlMethod){ | |
route(app.del, path, ctrlMethod); | |
} | |
function put(path, ctrlMethod){ | |
route(app.path, path, ctrlMethod); | |
} | |
// MAIN | |
function self(path, controller) { | |
get(path, controller.index); | |
get(path + '/new', controller.new) | |
post(path, controller.create); | |
get(path + '/:id', controller.show); | |
get(path + '/:id/edit', controller.edit); | |
put(path + '/:id', controller.update); | |
del(path + '/:id', controller.delete); | |
} | |
self.init = function(appRef) { | |
app = appRef; | |
} | |
return self; | |
}; |
This file contains hidden or 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 issues = require('./controllers/issues'); | |
var resource = require('./lib/resource'); | |
module.exports = function(app){ | |
resource.init(app); | |
resource('/issues', issues); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I wrote something similar in Coffeescript for my media manager thing. Also, Express 4.x uses a different syntax for fancy routing, although I don't think the way in your example is broken or deprecated.
in routes.coffee
in server.coffee
in controllers/foo.coffee
And here's the code to auto-wire-up all files in controllers/*