Skip to content

Commit

Permalink
Apply plugins for requests with callbacks
Browse files Browse the repository at this point in the history
Otherwise, the request is already sent by the time we apply the plugins with `request.use()`.
  • Loading branch information
shesek committed Jul 19, 2017
1 parent 0c87391 commit 3a8d0d2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ module.exports = function(_superagent) {
}
methods.forEach(function(method) {
superagent[method] = function() {
var request = _superagent[method].apply(superagent, arguments);
var args = [].slice.call(arguments), cb
if (typeof args[args.length-1] == 'function') {
cb = args[args.length-1]
args = args.slice(0, -1)
}
var request = _superagent[method].apply(superagent, args);
uses.forEach(function(use) {
request = request.use(use);
})
if (cb) request.end(cb)
return request;
};
});
Expand Down

0 comments on commit 3a8d0d2

Please sign in to comment.