Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added post and get variable coverage

  • Loading branch information...
commit 9c8db7a34139297d9ecf27e4cc59f6eab96f0f63 1 parent 8ac71e1
Dhaivat Pandya authored

Showing 3 changed files with 26 additions and 7 deletions. Show diff stats Hide diff stats

  1. +22 2 Birbal.js
  2. +0 1  example.js
  3. +4 4 package.json
24 Birbal.js
... ... @@ -1,6 +1,6 @@
1 1 var http = require("http");
2 2 var url = require("url");
3   -var jade = require("jade");
  3 +var qs = require("querystring");
4 4
5 5 var Birbal = function (routes) {
6 6
@@ -19,6 +19,26 @@ var Birbal = function (routes) {
19 19
20 20 this.onRequest = function (request, response, specials) {
21 21 var pathname = url.parse(request.url).pathname;
  22 +
  23 + var request_vars;
  24 +
  25 + if(request.method == 'POST') {
  26 + var body = ''
  27 + request.on('data', function(data) {
  28 + body += data;
  29 + });
  30 +
  31 + request.on('end', function() {
  32 + request_vars = qs.parse(body);
  33 + });
  34 + }
  35 +
  36 + else if(request.method == 'GET') {
  37 + var url_parts = url.parse(request.url, true);
  38 + var query = url_parts.query;
  39 +
  40 + request_vars = query;
  41 + }
22 42
23 43 var matched = false;
24 44 for(var i in routes) {
@@ -45,7 +65,7 @@ var Birbal = function (routes) {
45 65
46 66 if(this.specials["catchAllFunc"] != null && this.specials["catchAllFunc"] != undefined) {
47 67 response.writeHead(200, {"Content-Type":"text/html"});
48   - response.write(this.specials["catchAllFunc"]());
  68 + response.write(this.specials["catchAllFunc"](request_vars));
49 69 response.end();
50 70 }
51 71 }
1  example.js
@@ -17,7 +17,6 @@ function before() {
17 17
18 18 //called when no other request matches
19 19 function oops() {
20   - console.log("Type in the URL again!");
21 20 return "Oops!";
22 21 }
23 22
8 package.json
... ... @@ -1,17 +1,17 @@
1 1 {
2 2 "name" : "Birbal",
3   - "version" : "0.1",
  3 + "version" : "0.0.1",
4 4 "description":"Quick, simple routing",
5 5 "keywords":["routing", "router", "framework"],
6 6 "author":"Dhaivat Pandya <dhaivatpandya@gmail.com> (http://poincare101.blogspot.com)",
7 7 "repository" :
8   - { "type": "git"
  8 + { "type": "git",
9 9 "url" : "https://github.com/poincare/Birbal"
10 10 },
11 11 "bugs" :
12   - { "email" : "dhaivatpandya@gmail.com"
  12 + { "email" : "dhaivatpandya@gmail.com",
13 13 "url" : "http://github.com/poincare/Birbal/issues"
14 14 },
15   - "directories" : {"lib" : "./"},
  15 + "directories" : {"lib" : "./"}
16 16 }
17 17

0 comments on commit 9c8db7a

Please sign in to comment.
Something went wrong with that request. Please try again.