Comparing version 1.0.2 to 1.0.3
@@ -5,3 +5,4 @@ | ||
util = require('util'), | ||
director = require('../../director'); | ||
director = require('../../director'), | ||
responses = require('./responses'); | ||
@@ -12,4 +13,12 @@ // | ||
exports.methods = require('./methods'); | ||
exports.responses = require('./responses'); | ||
Object.keys(responses).forEach(function (name) { | ||
exports[name] = responses[name]; | ||
}) | ||
// | ||
// ### function Router (routes) | ||
// #### @routes {Object} **Optional** Routing table for this instance. | ||
// Constuctor function for the HTTP Router object responsible for building | ||
// and dispatching from a given routing table. | ||
// | ||
var Router = exports.Router = function (routes) { | ||
@@ -26,7 +35,5 @@ // | ||
this.extend(exports.methods); | ||
this.extend(exports.methods.concat(['before', 'after'])); | ||
this.configure(); | ||
this.mount(routes || {}); | ||
}; | ||
@@ -39,2 +46,10 @@ | ||
// | ||
// ### function on (method, path, route) | ||
// #### @method {string} **Optional** Method to use | ||
// #### @path {string} Path to set this route on. | ||
// #### @route {Array|function} Handler for the specified method and path. | ||
// Adds a new `route` to this instance for the specified `method` | ||
// and `path`. | ||
// | ||
Router.prototype.on = function (method, path) { | ||
@@ -50,3 +65,3 @@ var args = Array.prototype.slice.call(arguments, 2), | ||
director.Router.prototype.on.call(this, method, path, route); | ||
} | ||
}; | ||
@@ -118,2 +133,7 @@ // | ||
// | ||
// ### @parsers {Object} | ||
// Lookup table of parsers to use when attempting to | ||
// parse incoming responses. | ||
// | ||
Router.prototype.parsers = { | ||
@@ -124,2 +144,7 @@ 'application/x-www-form-urlencoded': qs.parse, | ||
// | ||
// ### function parse (req) | ||
// #### @req {http.ServerResponse|BufferedStream} Incoming HTTP request to parse | ||
// Attempts to parse `req.body` using the value found at `req.headers['content-type']`. | ||
// | ||
Router.prototype.parse = function (req) { | ||
@@ -135,10 +160,13 @@ function mime(req) { | ||
if (parser) { | ||
req.body = ''; | ||
req.chunks.forEach(function (chunk) { | ||
req.body += chunk; | ||
}); | ||
req.body = req.body || ''; | ||
if (req.chunks) { | ||
req.chunks.forEach(function (chunk) { | ||
req.body += chunk; | ||
}); | ||
} | ||
try { | ||
req.body = req.body | ||
? parser(data) | ||
req.body = req.body && req.body.length | ||
? parser(req.body) | ||
: {}; | ||
@@ -145,0 +173,0 @@ } |
@@ -151,5 +151,5 @@ /* | ||
this.every = { | ||
after: options.after || [], | ||
before: options.before || [], | ||
on: options.on || [] | ||
after: options.after || null, | ||
before: options.before || null, | ||
on: options.on || null | ||
}; | ||
@@ -310,6 +310,6 @@ | ||
Router.prototype.runlist = function (fns) { | ||
var runlist = this.every && this.every.before | ||
var runlist = this.every && this.every.before | ||
? [this.every.before].concat(_flatten(fns)) | ||
: _flatten(fns); | ||
if (this.every && this.every.on) { | ||
@@ -341,3 +341,2 @@ runlist.push(this.every.on); | ||
} | ||
next(); | ||
}, function () { | ||
@@ -381,2 +380,3 @@ // | ||
current, | ||
exact, | ||
match, | ||
@@ -416,9 +416,9 @@ next, | ||
// | ||
current = regexp + this.delimiter + r; | ||
current = exact = regexp + this.delimiter + r; | ||
if (!this.strict) { | ||
current += '[' + this.delimiter + ']?'; | ||
exact += '[' + this.delimiter + ']?'; | ||
} | ||
match = path.match(new RegExp('^' + current)); | ||
match = path.match(new RegExp('^' + exact)); | ||
@@ -425,0 +425,0 @@ if (!match) { |
@@ -5,3 +5,3 @@ { | ||
"author": "Nodejitsu Inc <info@nodejitsu.com>", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"contributors": [ | ||
@@ -8,0 +8,0 @@ { "name": "Paolo Fragomeni", "email": "hij1nx@nodejitsu.com" }, |
@@ -7,2 +7,16 @@ /* | ||
* | ||
*/ | ||
*/ | ||
var assert = require('assert'), | ||
vows = require('vows'), | ||
director = require('../../../lib/director'); | ||
vows.describe('director/http/responses').addBatch({ | ||
"When using director.http": { | ||
"it should have the relevant responses defined": function () { | ||
Object.keys(require('../../../lib/director/http/responses')).forEach(function (name) { | ||
assert.isFunction(director.http[name]); | ||
}); | ||
} | ||
} | ||
}).export(module); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
233384
3655