Skip to content

Instantly share code, notes, and snippets.

@ded
Created October 21, 2011 23:14
Show Gist options
  • Save ded/1305237 to your computer and use it in GitHub Desktop.
Save ded/1305237 to your computer and use it in GitHub Desktop.
Rails-like routes for Express
var express = require('express')
, app = express.createServer()
require('./config/routes').initialize(app)
module.exports = {
index: function (req, res, next) {
res.render('index', {
title: 'Express'
})
}
}
module.exports.initialize = function (app) {
function match(method, route, controller, action) {
app[method](route, function (req, res, next) {
require('../controllers/' + controller)[action || 'index'](req, res, next)
})
}
match('get', '/', 'application', 'index')
}
@ded
Copy link
Author

ded commented Oct 22, 2011

they've always been sync as far as I know. With regards to this example, it definitely works, you should try it out on a default Express install

@skw
Copy link

skw commented Apr 11, 2013

express-coffee does something similar with express in CS, I'm kinda on the fence about using CS but it is a pleasure to work with...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment