jonsamwell / angular-http-batcher

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

relative urls don't work #4

Closed goleafs closed 9 years ago

goleafs commented 9 years ago

all of our api endpoints are relative, e.g. var svc = $resource('/api/customers');

the batcher does not like this and ends up mutating calls to: http://pi/customers host: pi

I fixed this in the getUrlInfo - we can just use $location.host() and $location.provider() and the url coming in is already the relativeurl.

                    getUrlInfo = function (url) {

                        return {
                            protocol: constants.protocol,
                            host: constants.host, 
                            relativeUrl: url 
                        };

                    }

and now this works with this configuration:

httpBatchConfigProvider.setAllowedBatchEndpoint('/api', '/api/batch');

It would probably be better to make this a configuration option and/or inspect the url more closely in getUrlInfo() to see if it is already relative in which case to use the $location protocol/host.

jonsamwell commented 9 years ago

Add support for URL - please give it a test and see if it works for you. This has been pushed up to bower v1.3.0