Comparing version 1.0.5 to 1.0.6
@@ -51,5 +51,11 @@ (function () { | ||
} else { | ||
if (call.name !== undefined) { | ||
options.routeName = call.name; | ||
} | ||
if (call.init !== undefined) { | ||
options.appServer = this; | ||
call.init(options); | ||
} | ||
if (call.plugin !== undefined) { | ||
@@ -62,15 +68,31 @@ options.call = call.plugin; | ||
case 'pre': | ||
this.pre.push(options); | ||
if (options.top === true) { | ||
this.pre.unshift(options); | ||
} else { | ||
this.pre.push(options); | ||
} | ||
break; | ||
case 'post': | ||
this.post.push(options); | ||
if (options.top === true) { | ||
this.post.unshift(options); | ||
} else { | ||
this.post.push(options); | ||
} | ||
break; | ||
case 'final': | ||
this.final.push(options); | ||
if (options.top === true) { | ||
this.final.unshift(options); | ||
} else { | ||
this.final.push(options); | ||
} | ||
break; | ||
default: | ||
this.main.push(options); | ||
if (options.top === true) { | ||
this.main.unshift(options); | ||
} else { | ||
this.main.push(options); | ||
} | ||
} | ||
@@ -98,3 +120,7 @@ | ||
} | ||
if (typeof(this.options.callRoute) === 'function') { | ||
res.callRoute = this.options.callRoute; | ||
} | ||
for (var i = 0; i < this.eventHandlers.length; i++) { | ||
@@ -101,0 +127,0 @@ res.on(this.eventHandlers[i].event, this.eventHandlers[i].handler); |
@@ -7,2 +7,4 @@ (function () { | ||
}; | ||
exports.name = 'default 404 handler'; | ||
})(); |
@@ -28,2 +28,4 @@ (function () { | ||
}; | ||
exports.name = 'default logger'; | ||
})(); |
@@ -9,2 +9,4 @@ (function () { | ||
exports.name = 'default file handler'; | ||
exports.init = function (options) { | ||
@@ -11,0 +13,0 @@ options = options || { }; |
@@ -6,2 +6,4 @@ (function () { | ||
exports.name = 'default redirect handler'; | ||
exports.init = function (options) { | ||
@@ -8,0 +10,0 @@ routes = options.routes; |
@@ -6,2 +6,3 @@ (function () { | ||
exports.name = 'default session handler'; | ||
@@ -8,0 +9,0 @@ exports.plugin = function (request, response, options) { |
@@ -26,2 +26,3 @@ (function () { | ||
this.checkRoute = this.defaultCheckRoute; | ||
this.callRoute = this.defaultCallRoute; | ||
} | ||
@@ -53,2 +54,6 @@ | ||
Response.prototype.defaultCallRoute = function (func, request, response, options) { | ||
func(request, response, options); | ||
}; | ||
Response.prototype.next = function () { | ||
@@ -72,3 +77,3 @@ if (this._croute >= this._routes.length) { | ||
try { | ||
next.call(this._actual.request, this, next); | ||
this.callRoute(next.call, this._actual.request, this, next); | ||
} catch (error) { | ||
@@ -107,3 +112,3 @@ this.emit('run.fatal', error); | ||
if (this._croute === 2) { | ||
if (this._croute === 3) { | ||
var length = 0; | ||
@@ -110,0 +115,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Bricks Application Server", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"homepage": "http://bricksjs.com/", | ||
@@ -20,5 +20,5 @@ "preferGlobal": "true", | ||
"cookies": "~0.1.6", | ||
"mime": "~1.2.2", | ||
"mime": ">=1.2.2", | ||
"date-utils": ">1.0.0", | ||
"optimist": "~0.2", | ||
"optimist": ">=0.2", | ||
"node-uuid": "~1.1.0", | ||
@@ -28,3 +28,3 @@ "eventemitter2": "~0.2.6" | ||
"devDependencies": { | ||
"vows": "~0.5.0" | ||
"vows": ">=0.5.0" | ||
}, | ||
@@ -31,0 +31,0 @@ "directories": { |
var vows = require('vows'), | ||
assert = require('assert'), | ||
server = require('../lib/appserver'); | ||
server = require('../lib/appserver'), | ||
mrequest = require('./mocks/request'), | ||
mresponse = require('./mocks/response'); | ||
@@ -74,3 +77,199 @@ vows.describe('Add Routes').addBatch({ | ||
} | ||
}, | ||
'a route added to pre as top': { | ||
topic: function () { | ||
var thisp = this; | ||
var appserver = new server.appserver({ checkRoute: function () { return true; } }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
thisp.callback('wrong one'); | ||
}, { section: "pre" }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
thisp.callback("ok"); | ||
}, { section: "pre", top: true }); | ||
var res = new mresponse.response(); | ||
var req = new mrequest.request(); | ||
req.url = "/bar"; | ||
appserver.handleRequest(req, res, appserver); | ||
}, | ||
'fires in the correct order': function (err, request, response, options) { | ||
assert.equal(err, "ok"); | ||
} | ||
}, | ||
'a route added to main as top': { | ||
topic: function () { | ||
var thisp = this; | ||
var appserver = new server.appserver({ checkRoute: function () { return true; } }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
thisp.callback('wrong one'); | ||
}, { section: "main" }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
thisp.callback("ok"); | ||
}, { section: "main", top: true }); | ||
var res = new mresponse.response(); | ||
var req = new mrequest.request(); | ||
req.url = "/bar"; | ||
appserver.handleRequest(req, res, appserver); | ||
}, | ||
'fires in the correct order': function (err, request, response, options) { | ||
assert.equal(err, "ok"); | ||
} | ||
}, | ||
'a route added to post as top': { | ||
topic: function () { | ||
var thisp = this; | ||
var appserver = new server.appserver({ checkRoute: function () { return true; } }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
thisp.callback('wrong one'); | ||
}, { section: "post" }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
thisp.callback("ok"); | ||
}, { section: "post", top: true }); | ||
var res = new mresponse.response(); | ||
var req = new mrequest.request(); | ||
req.url = "/bar"; | ||
appserver.handleRequest(req, res, appserver); | ||
}, | ||
'fires in the correct order': function (err, request, response, options) { | ||
assert.equal(err, "ok"); | ||
} | ||
}, | ||
'a route added to final as top': { | ||
topic: function () { | ||
var thisp = this; | ||
var appserver = new server.appserver({ checkRoute: function () { return true; } }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
thisp.callback('wrong one'); | ||
}, { section: "final" }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
thisp.callback("ok"); | ||
}, { section: "final", top: true }); | ||
var res = new mresponse.response(); | ||
var req = new mrequest.request(); | ||
req.url = "/bar"; | ||
appserver.handleRequest(req, res, appserver); | ||
}, | ||
'fires in the correct order': function (err, request, response, options) { | ||
assert.equal(err, "ok"); | ||
} | ||
}, | ||
'a route added to pre': { | ||
topic: function () { | ||
var thisp = this; | ||
var appserver = new server.appserver({ checkRoute: function () { return true; } }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
try { | ||
response.write('test'); | ||
thisp.callback("ok"); | ||
} catch (error) { | ||
thisp.callback("error"); | ||
} | ||
}, { section: "pre" }); | ||
var res = new mresponse.response(); | ||
var req = new mrequest.request(); | ||
req.url = "/bar"; | ||
appserver.handleRequest(req, res, appserver); | ||
}, | ||
'can write without error': function (err, request, response, options) { | ||
assert.equal(err, "ok"); | ||
} | ||
}, | ||
'a route added to main': { | ||
topic: function () { | ||
var thisp = this; | ||
var appserver = new server.appserver({ checkRoute: function () { return true; } }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
try { | ||
response.write('test'); | ||
thisp.callback("ok"); | ||
} catch (error) { | ||
thisp.callback("error"); | ||
} | ||
}, { section: "main" }); | ||
var res = new mresponse.response(); | ||
var req = new mrequest.request(); | ||
req.url = "/bar"; | ||
appserver.handleRequest(req, res, appserver); | ||
}, | ||
'can write without error': function (err, request, response, options) { | ||
assert.equal(err, "ok"); | ||
} | ||
}, | ||
'a route added to post': { | ||
topic: function () { | ||
var thisp = this; | ||
var appserver = new server.appserver({ checkRoute: function () { return true; } }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
try { | ||
response.write('test'); | ||
thisp.callback("ok"); | ||
} catch (error) { | ||
thisp.callback("error"); | ||
} | ||
}, { section: "post" }); | ||
var res = new mresponse.response(); | ||
var req = new mrequest.request(); | ||
req.url = "/bar"; | ||
appserver.handleRequest(req, res, appserver); | ||
}, | ||
'can write without error': function (err, request, response, options) { | ||
assert.equal(err, "ok"); | ||
} | ||
}, | ||
'a route added to final': { | ||
topic: function () { | ||
var thisp = this; | ||
var appserver = new server.appserver({ checkRoute: function () { return true; } }); | ||
appserver.addRoute(".+", function (request, response, options) { | ||
try { | ||
response.write('test'); | ||
thisp.callback("ok"); | ||
} catch (error) { | ||
thisp.callback("error"); | ||
} | ||
}, { section: "final" }); | ||
var res = new mresponse.response(); | ||
var req = new mrequest.request(); | ||
req.url = "/bar"; | ||
appserver.handleRequest(req, res, appserver); | ||
}, | ||
'cannot write without error': function (err, request, response, options) { | ||
assert.equal(err, "error"); | ||
} | ||
} | ||
}).export(module); |
@@ -89,5 +89,2 @@ var vows = require('vows'), | ||
// appserver.addRoute(".+", function (request, response, options) { | ||
// thisp.callback(undefined, request, response, options); | ||
// }); | ||
setTimeout(function() { thisp.callback('callback not fired'); }, 50); | ||
@@ -94,0 +91,0 @@ var res = new mresponse.response(); |
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
51663
26
1060
+ Addedmime@4.0.6(transitive)
+ Addedminimist@0.0.10(transitive)
+ Addedoptimist@0.6.1(transitive)
- Removedmime@1.2.11(transitive)
- Removedoptimist@0.2.8(transitive)
Updatedmime@>=1.2.2
Updatedoptimist@>=0.2