Skip to content
Browse files

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

…bles.
  • Loading branch information...
1 parent 8f7a31d commit 6ca65014f4c9ddff8d3b5941924566706fd3fd44 @twentyrogersc committed
Showing with 7 additions and 2 deletions.
  1. +7 −2 index.js
View
9 index.js
@@ -97,6 +97,11 @@ 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
@@ -104,7 +109,7 @@ app.listen = function(port) {
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)
})
@@ -112,7 +117,7 @@ app.get = function(route, cb) {
}
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.
Something went wrong with that request. Please try again.