Created
December 12, 2016 09:40
-
-
Save blackrabbit99/21f407d4528bd9ff3f115cbff812dc32 to your computer and use it in GitHub Desktop.
Proxy csrf
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
const handler = { | |
get (target, propKey){ | |
if(propKey === 'post'){ | |
return function(...args){ | |
if(!args[args.length - 1].hasOwnProperty('csrfToken') || !args[args.length - 1].hasOwnProperty('cookie')){ | |
return target[propKey](...args) | |
} | |
const csrf = args.pop(); | |
return target[propKey](...args) | |
.set('x-xsrf-token', csrf.csrfToken) | |
.set('cookie', csrf.cookie); | |
} | |
} | |
return target[propKey]; | |
} | |
}; | |
request = new Proxy(request, handler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment