Skip to content

Commit

Permalink
Return top level function for JSGI middleware modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Dec 13, 2011
1 parent cd82c1b commit b9e0f97
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 12 deletions.
4 changes: 3 additions & 1 deletion jsgi/auth.js
Expand Up @@ -9,7 +9,7 @@ var AccessError = require("perstore/errors").AccessError,
print = require("promised-io/process").print,
base64 = require("../util/base64");

exports.Authentication = function(security, nextApp){
var Authentication = function(security, nextApp){
// initialize the user model
security.getUserModel();
return function(request){
Expand Down Expand Up @@ -61,3 +61,5 @@ exports.Authentication = function(security, nextApp){

};
};
Authentication.Authentication = Authentication;
module.exports = Authentication;
4 changes: 3 additions & 1 deletion jsgi/cascade.js
Expand Up @@ -4,7 +4,7 @@
*/
var defer = require("promised-io/promise").defer,
when = require("promised-io/promise").when;
var Cascade = exports.Cascade = function(apps, status) {
var Cascade = function(apps, status) {
status = status || 404;

return function(env) {
Expand Down Expand Up @@ -34,3 +34,5 @@ var Cascade = exports.Cascade = function(apps, status) {
return deferred.promise;
}
}
Cascade.Cascade = Cascade;
module.exports = Cascade;
4 changes: 3 additions & 1 deletion jsgi/class-alias.js
@@ -1,6 +1,6 @@
var classModel = require('model').classModel;

exports.Handler = function(nextApp) {
var Handler = function(nextApp) {
return function(request) {
try {
var modelPath = request.pathInfo.substring(1);
Expand All @@ -10,3 +10,5 @@ exports.Handler = function(nextApp) {
return nextApp(request);
};
};
Handler.Handler = Handler;
module.exports = Handler;
4 changes: 3 additions & 1 deletion jsgi/compress.js
Expand Up @@ -3,7 +3,7 @@
*/
var when = require("promised-io/promise").when;

exports.Compress = function(nextApp){
var Compress = function(nextApp){
return function(request){
var encoding = 'gzip';
if ((request.headers['accept-encoding']||'').indexOf(encoding) >= 0) {
Expand Down Expand Up @@ -53,3 +53,5 @@ exports.Compress = function(nextApp){
return nextApp(request);
};
};
Compress.Compress = Compress;
module.exports = Compress;
4 changes: 3 additions & 1 deletion jsgi/conditional.js
Expand Up @@ -3,7 +3,7 @@
*/
var DatabaseError = require("perstore/errors").DatabaseError,
when = require("promised-io/promise").when;
exports.Conditional = function(onlyHandleGet, nextApp){
var Conditional = function(onlyHandleGet, nextApp){
return function(request){
if(!onlyHandleGet && request.method !== "GET"){
// onlyHandleGet is appropriate when an error really needs to be thrown to
Expand Down Expand Up @@ -53,3 +53,5 @@ exports.Conditional = function(onlyHandleGet, nextApp){
});
};
}
Conditional.Conditional = Conditional;
module.exports = Conditional;
4 changes: 3 additions & 1 deletion jsgi/context.js
Expand Up @@ -2,7 +2,7 @@
* Provides the request as the context (across async promises)
*/
var promiseModule = require("promised-io/promise");
exports.SetContext= function(vars, nextApp){
var SetContext = function(vars, nextApp){
return function(request){
try{
promiseModule.currentContext = request.context = ((typeof vars === 'function') ? vars(request) : vars) || {};
Expand All @@ -13,3 +13,5 @@ exports.SetContext= function(vars, nextApp){
}
};
};
SetContext.SetContext = SetContext;
module.exports = SetContext;
5 changes: 4 additions & 1 deletion jsgi/csrf.js
Expand Up @@ -2,7 +2,7 @@
* Detects cross-site forgeable requests and warns downstream middleware/apps
* by adding a crossSiteForgeable property to the request
*/
exports.CSRFDetect = function(customHeader, nextApp){
var CSRFDetect = function(customHeader, nextApp){
if(typeof customHeader == "function"){
nextApp = customHeader;
}
Expand All @@ -17,3 +17,6 @@ exports.CSRFDetect = function(customHeader, nextApp){
return nextApp(request);
};
};

CSRFDetect.CSRFDetect = CSRFDetect;
module.exports = CSRFDetect;
11 changes: 6 additions & 5 deletions jsgi/xsite.js
Expand Up @@ -5,12 +5,12 @@
var parseQuery = require("./querystring").parseQuery,
when = require("promised-io/promise").when;

exports.CrossSite = function(nextApp){
var CrossSite = function(nextApp){
return JsonP(
WindowName(
CrossSiteXhr(nextApp)));
};

CrossSite.CrossSite = CrossSite;

function JsonP(nextApp){
return function(request){
Expand All @@ -36,7 +36,7 @@ function JsonP(nextApp){
// TODO: Handle 401 with a dialog to enter credentials
};
};
exports.JsonP = JsonP;
CrossSite.JsonP = JsonP;

function WindowName(nextApp){
return function(request){
Expand All @@ -62,7 +62,7 @@ function WindowName(nextApp){
return nextApp(request);
};
};
exports.WindowName = WindowName;
CrossSite.WindowName = WindowName;

function CrossSiteXhr(nextApp){
return function(request, allowed){
Expand Down Expand Up @@ -99,4 +99,5 @@ function CrossSiteXhr(nextApp){
};
};

exports.CrossSiteXhr = CrossSiteXhr;
CrossSite.CrossSiteXhr = CrossSiteXhr;
module.exports = CrossSite;

0 comments on commit b9e0f97

Please sign in to comment.