jonsamwell / angular-http-batcher

Enables HTTP batch request with AngularJS
MIT License
96 stars 28 forks source link

Easy way to disable batcher for development and testing #13

Closed sarg3nt closed 9 years ago

sarg3nt commented 9 years ago

I've ran into a case where the batcher is breaking our login checking system. As part of troubleshooting this I wanted to shut off the batcher but can't find an easy of doing so (without commenting out the main js file, the config js file and the line where we inject it into the app, which is kind of painful. Is there a way to do this in the config? I tried setting maxBatchedRequestPerCall to 1 but that didn't do it. If not, can we get a config option that would completely turn off batching for testing?

jonsamwell commented 9 years ago

This seems sensible although I would have thought setting maxBatchedRequestPerCall to 0 would have done the trick. Let me investigate.

Jon

sarg3nt commented 9 years ago

Me too, but it doesn't instead it batches each request into a single one to /batch

sarg3nt commented 9 years ago

Whops sorry, that close and comment button is way to easy to hit.

sarg3nt commented 9 years ago

This was becoming more and more of an issue as we troubhshoot things so I mucked around in your code and did the following:

this.canBatchCall = function (url, method) {
            var config = this.getBatchConfig(url);
            return config !== undefined &&
                config.batchEndpointUrl !== url &&
                config.ignoredVerbs.indexOf(method.toLowerCase()) === -1 &&
                config.maxBatchedRequestPerCall > 0;
        };

See the last line. If maxBatchedRequestPerCall is zero, it will now not batch the any requests. Not sure if that's the way you would do it or not, but works for me for now.

jonsamwell commented 9 years ago

This seems a reasonable approach. Sorry I have been so busy lately at work and outside. Things are starting to settle down from next week so I will be able to tackle these issues.

jonsamwell commented 9 years ago

The config option now has an enabled flag. Set to false to disable.

    app.config([
            'httpBatchConfigProvider',
            function (httpBatchConfigProvider) {
                httpBatchConfigProvider.setAllowedBatchEndpoint(
                        'http://localhost:8080',
                        'http://localhost:8080/api/batch', {
                            batchRequestCollectionDelay: 500,
                            minimumBatchSize: 2,
                            sendCookies: true,
                            enabled: false
                        });
            }
    ]);