Created
December 4, 2011 23:41
-
-
Save geek0x23/1431671 to your computer and use it in GitHub Desktop.
A wrapper for the default connect/express csrf middleware that adds ignore support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
_ = require('underscore'), | |
parse = require('url').parse; | |
exports = module.exports = load; | |
exports.ignore = ['/api/method1', '/api/method2']; | |
function load(options) { | |
var defaultCsrf = express.csrf(options); | |
return function load(req, res, next) { | |
if (exports.ignore.length > 0) { | |
var reqPath = parse(req.url).pathname, | |
ignore = false; | |
_.each(exports.ignore, function(ignorePath) { | |
if (~reqPath.indexOf(ignorePath)) { | |
ignore = true; | |
return; | |
} | |
}); | |
} | |
if (ignore) { | |
return next(); | |
} else { | |
return defaultCsrf(req, res, next); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment