Permalink
Browse files

Added post and get variable coverage

  • Loading branch information...
1 parent 8ac71e1 commit 9c8db7a34139297d9ecf27e4cc59f6eab96f0f63 @Poincare committed Dec 16, 2011
Showing with 26 additions and 7 deletions.
  1. +22 −2 Birbal.js
  2. +0 −1 example.js
  3. +4 −4 package.json
View
@@ -1,6 +1,6 @@
var http = require("http");
var url = require("url");
-var jade = require("jade");
+var qs = require("querystring");
var Birbal = function (routes) {
@@ -19,6 +19,26 @@ var Birbal = function (routes) {
this.onRequest = function (request, response, specials) {
var pathname = url.parse(request.url).pathname;
+
+ var request_vars;
+
+ if(request.method == 'POST') {
+ var body = ''
+ request.on('data', function(data) {
+ body += data;
+ });
+
+ request.on('end', function() {
+ request_vars = qs.parse(body);
+ });
+ }
+
+ else if(request.method == 'GET') {
+ var url_parts = url.parse(request.url, true);
+ var query = url_parts.query;
+
+ request_vars = query;
+ }
var matched = false;
for(var i in routes) {
@@ -45,7 +65,7 @@ var Birbal = function (routes) {
if(this.specials["catchAllFunc"] != null && this.specials["catchAllFunc"] != undefined) {
response.writeHead(200, {"Content-Type":"text/html"});
- response.write(this.specials["catchAllFunc"]());
+ response.write(this.specials["catchAllFunc"](request_vars));
response.end();
}
}
View
@@ -17,7 +17,6 @@ function before() {
//called when no other request matches
function oops() {
- console.log("Type in the URL again!");
return "Oops!";
}
View
@@ -1,17 +1,17 @@
{
"name" : "Birbal",
- "version" : "0.1",
+ "version" : "0.0.1",
"description":"Quick, simple routing",
"keywords":["routing", "router", "framework"],
"author":"Dhaivat Pandya <dhaivatpandya@gmail.com> (http://poincare101.blogspot.com)",
"repository" :
- { "type": "git"
+ { "type": "git",
"url" : "https://github.com/poincare/Birbal"
},
"bugs" :
- { "email" : "dhaivatpandya@gmail.com"
+ { "email" : "dhaivatpandya@gmail.com",
"url" : "http://github.com/poincare/Birbal/issues"
},
- "directories" : {"lib" : "./"},
+ "directories" : {"lib" : "./"}
}

0 comments on commit 9c8db7a

Please sign in to comment.