freeCodeCamp/server/middlewares/csurf.js

13 lines
285 B
JavaScript
Raw Normal View History

2016-05-03 00:22:56 +00:00
import csurf from 'csurf';
export default function() {
2016-05-03 04:11:49 +00:00
const protection = csurf({ cookie: true });
return function csrf(req, res, next) {
const path = req.path.split('/')[1];
if (/api/.test(path)) {
return next();
}
return protection(req, res, next);
};
2016-05-03 00:22:56 +00:00
}