diff --git a/server.js b/server.js index ccb1fd5..0581573 100644 --- a/server.js +++ b/server.js @@ -4,8 +4,14 @@ global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; var noConflictSelf = global.self; global.self = {}; require('whatwg-fetch'); -global.fetch = global.self.fetch; global.Headers = global.self.Headers; global.Request = global.self.Request; global.Response = global.self.Response; +var realFetch = global.self.fetch; +global.fetch = function(url, options) { + if (/^\/\//.test(url)) { + url = 'https:' + url; + } + return realFetch.call(this, url, options); +}; global.self = noConflictSelf; diff --git a/test/api.test.js b/test/api.test.js index 57d3e41..b87fb03 100644 --- a/test/api.test.js +++ b/test/api.test.js @@ -28,21 +28,23 @@ describe('fetch', function() { }); it('should facilitate the making of requests', function(done) { - fetch('https://mattandre.ws/succeed.txt') + fetch('//mattandre.ws/succeed.txt') .then(responseToText) .then(function(data) { expect(data).to.equal(good); done(); - }); + }) + .catch(done); }); it('should do the right thing with bad requests', function(done) { - fetch('https://mattandre.ws/fail.txt') + fetch('//mattandre.ws/fail.txt') .then(responseToText) .catch(function(err) { expect(err.toString()).to.equal("Error: Bad server response"); done(); - }); + }) + .catch(done); }); });