mixdown-router
Advanced tools
Comparing version 4.0.4 to 4.0.5
var _ = require('lodash'); | ||
var verbs = ['get', 'post', 'put', 'delete']; | ||
var non_manifest_properties = ['browser_handler', 'dir_path']; | ||
var manifest_properties = ['authenticate', 'authorize', 'name', 'path', 'timeout', 'description', 'params', 'browser', 'cache_buster']; | ||
var manifest_properties = ['authenticate', 'authorize', 'name', 'path', 'timeout', 'description', 'params', 'browser', 'cache_buster', 'session']; | ||
var controller_properties = non_manifest_properties.concat(verbs.concat(manifest_properties)); | ||
var parse_params = require('./parse_params.js'); | ||
var Controller = function(rawController) { | ||
var Controller = function (rawController) { | ||
@@ -27,3 +27,3 @@ if (!(this instanceof Controller)) { | ||
_.each(this.params, function(p, name) { | ||
_.each(this.params, function (p, name) { | ||
@@ -51,7 +51,7 @@ p.name = name; //set this so it is accessible inside the param spec. | ||
Controller.prototype.evaluate = function(strUrl) { | ||
Controller.prototype.evaluate = function (strUrl) { | ||
return this.urlformat.test(strUrl); | ||
}; | ||
Controller.prototype.parse = function(httpContext) { | ||
Controller.prototype.parse = function (httpContext) { | ||
@@ -61,4 +61,4 @@ // LOAD httpContext.params | ||
// validate and attach blessed query params. Non-declared will still exist on httpContext.url. | ||
_.each(this.queryParams, function(p, name) { | ||
if (typeof(httpContext.url.query[name]) !== 'undefined' && p.regex.test(httpContext.url.query[name])) { | ||
_.each(this.queryParams, function (p, name) { | ||
if (typeof (httpContext.url.query[name]) !== 'undefined' && p.regex.test(httpContext.url.query[name])) { | ||
httpContext.params[name] = httpContext.url.query[name]; | ||
@@ -77,3 +77,3 @@ } else if (p['default']) { | ||
// validate and attach rest params. | ||
_.each(this.restParams, function(pmap, i) { | ||
_.each(this.restParams, function (pmap, i) { | ||
var param = urlParams[i]; | ||
@@ -92,3 +92,3 @@ if (param && pmap) { | ||
Controller.prototype.manifest = function() { | ||
Controller.prototype.manifest = function () { | ||
var self = this; | ||
@@ -98,7 +98,7 @@ var manifest_entry = _.pick(this, manifest_properties); | ||
// return boolean noting whether this supports each verb. | ||
_.each(verbs, function(v) { | ||
_.each(verbs, function (v) { | ||
manifest_entry[v] = self.hasOwnProperty(v); | ||
}); | ||
manifest_entry.browser = (typeof(this.browser_handler) === 'function'); | ||
manifest_entry.browser = (typeof (this.browser_handler) === 'function'); | ||
@@ -109,13 +109,13 @@ return manifest_entry; | ||
Controller.prototype.handle = function(httpContext) { | ||
Controller.prototype.handle = function (httpContext) { | ||
var method = httpContext.request.method.toLowerCase(); | ||
// if browser, then handle | ||
if (typeof(window) !== 'undefined' && this.browser) { | ||
if (typeof (window) !== 'undefined' && this.browser) { | ||
this.browser_handler.call(httpContext.app, httpContext) | ||
} else if (typeof(window) !== 'undefined' && window.location.href !== httpContext.request.url) { | ||
} else if (typeof (window) !== 'undefined' && window.location.href !== httpContext.request.url) { | ||
window.location.href = httpContext.request.url; | ||
} else if (typeof(this[method]) === 'function') { | ||
} else if (typeof (this[method]) === 'function') { | ||
this[method].call(httpContext.app, httpContext); | ||
@@ -130,2 +130,2 @@ | ||
module.exports = Controller; | ||
module.exports = Controller; |
{ | ||
"name": "mixdown-router", | ||
"version": "4.0.4", | ||
"version": "4.0.5", | ||
"description": "Router for mixdown.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
70808
1702