Skip to content

Commit

Permalink
Support //mattandre.ws URLs on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-andrews committed Jan 21, 2015
1 parent 458e4f6 commit 81bbf3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
10 changes: 6 additions & 4 deletions test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});

0 comments on commit 81bbf3c

Please sign in to comment.