Skip to content

Commit 6cb9ea6

Browse files
Merge pull request #10 from matthew-andrews/slashslash
Support //mattandre.ws URLs on the server
2 parents 458e4f6 + 81bbf3c commit 6cb9ea6

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

server.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
44
var noConflictSelf = global.self;
55
global.self = {};
66
require('whatwg-fetch');
7-
global.fetch = global.self.fetch;
87
global.Headers = global.self.Headers;
98
global.Request = global.self.Request;
109
global.Response = global.self.Response;
10+
var realFetch = global.self.fetch;
11+
global.fetch = function(url, options) {
12+
if (/^\/\//.test(url)) {
13+
url = 'https:' + url;
14+
}
15+
return realFetch.call(this, url, options);
16+
};
1117
global.self = noConflictSelf;

test/api.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,23 @@ describe('fetch', function() {
2828
});
2929

3030
it('should facilitate the making of requests', function(done) {
31-
fetch('https://mattandre.ws/succeed.txt')
31+
fetch('//mattandre.ws/succeed.txt')
3232
.then(responseToText)
3333
.then(function(data) {
3434
expect(data).to.equal(good);
3535
done();
36-
});
36+
})
37+
.catch(done);
3738
});
3839

3940
it('should do the right thing with bad requests', function(done) {
40-
fetch('https://mattandre.ws/fail.txt')
41+
fetch('//mattandre.ws/fail.txt')
4142
.then(responseToText)
4243
.catch(function(err) {
4344
expect(err.toString()).to.equal("Error: Bad server response");
4445
done();
45-
});
46+
})
47+
.catch(done);
4648
});
4749

4850
});

0 commit comments

Comments
 (0)