jonsamwell / angular-http-batcher

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

Absolute URL in config does not work #12

Closed sarg3nt closed 9 years ago

sarg3nt commented 9 years ago

I blew about three hours trying to figure out why the batcher wasn't working after first installing it in our code base. I followed the initial setup to a tee and confirmed the Web API was working as expected. I ended up creating a whole separate Angular app to test it and still couldn't get it to work until I switched the absolute URL's shown in the demo to relative ones. Once I did that, it began to work. Does not work:

    angular.module('app').config(['httpBatchConfigProvider',
        function (httpBatchConfigProvider) {
            httpBatchConfigProvider.setAllowedBatchEndpoint(
                // root endpoint url
                'https://url.whatever.com/api',
                // endpoint batch address
                'https://url.whatever.com/api/batch',

                // optional configuration parameters
                {
                    maxBatchedRequestPerCall: 30
                }
            );
        }
    ]);

Works:

    angular.module('app').config(['httpBatchConfigProvider',
        function (httpBatchConfigProvider) {
            httpBatchConfigProvider.setAllowedBatchEndpoint(
                // root endpoint url
                '/api',
                // endpoint batch address
                '/api/batch',

                // optional configuration parameters
                {
                    maxBatchedRequestPerCall: 30
                }
            );
        }
    ]);

I'm totally OK with the relative paths, it's really what I wanted anyway but was trying to replicate the exact setup as shown in the instructions to get it up and running. I don't know if this is a bug in the code base or not, but changing the instructions would be very helpful.

Thanks!

jonsamwell commented 9 years ago

This must be a matching issue when it is determining if it can batch a http request. Let me check this.

jonsamwell commented 9 years ago

This seems to be working in the test application?

https://github.com/jonsamwell/angular-http-batcher/blob/master/tests/index.html#L34

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