Permalink
Browse files

Adding routes through one function, ready for crossroad pattern varia…

…bles.
  • Loading branch information...
twentyrogersc committed May 18, 2012
1 parent 8f7a31d commit 6ca65014f4c9ddff8d3b5941924566706fd3fd44
Showing with 7 additions and 2 deletions.
  1. +7 −2 index.js
View
@@ -97,22 +97,27 @@ var server = function(req, res) {
crossroads.parse(route, [req, res])
}
+var addRoute = function(method, route, cb) {
+ route = method+' '+route
+ crossroads.addRoute(route, cb);
+}
+
app.listen = function(port) {
http.createServer(server).listen(port)
return app
}
app.get = function(route, cb) {
- crossroads.addRoute('GET '+route, function(req, res) {
+ addRoute('GET', route, function(req, res) {
req.query = qs.parse(req.url.query)
cb(req, res)
})
return app
}
app.post = function(route, cb) {
- crossroads.addRoute('POST '+route, function(req, res) {
+ addRoute('POST', route, function(req, res) {
var form = new formidable.IncomingForm()
form.parse(req, function(err, fields, files) {
req.body = fields

0 comments on commit 6ca6501

Please sign in to comment.