forked from qubyte/fetch-ponyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-node.js
More file actions
27 lines (23 loc) · 921 Bytes
/
fetch-node.js
File metadata and controls
27 lines (23 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use strict';
var wrapFetchForNode = function (fetch) {
// Support schemaless URIs on the server for parity with the browser.
// https://github.com/matthew-andrews/isomorphic-fetch/pull/10
return function (url, options) {
if (url.slice(0, 2) === '//') {
url = 'https:' + url;
}
return fetch.call(undefined, url, options);
};
};
module.exports = function (context) {
var fetch = require('node-fetch');
// This modifies the global `node-fetch` object, which isn't great, since
// different callers to `fetch-ponyfill` which pass a different Promise
// implementation would each expect to have their implementation used. But,
// given the way `node-fetch` is implemented, this is the only way to make
// it work at all.
if (context && context.Promise) {
fetch.Promise = context.Promise;
}
return wrapFetchForNode(fetch);
};