@@ -7,22 +7,11 @@ define('fetch/setup', ['exports'], function(self) {
77 'abortcontroller-polyfill/dist/cjs-ponyfill'
88 ) ;
99 var nodeFetch = FastBoot . require ( 'node-fetch' ) ;
10- var abortableFetch = AbortControllerPolyfill . abortableFetch ( {
11- fetch : nodeFetch ,
12- Request : nodeFetch . Request
13- } ) ;
1410
1511 self [ 'default' ] = function ( protocol , host ) {
1612 return function ( ) {
1713 define ( 'fetch' , [ 'exports' ] , function ( exports ) {
18- /**
19- * Setup the exported fetch for a given origin so it can handle:
20- * - protocol-relative URL (//can-be-http-or-https.com/)
21- * - path-relative URL (/file/under/root)
22- * @param {String } url
23- * @param {Object } [options]
24- */
25- exports [ 'default' ] = function fetch ( url , options ) {
14+ function buildAbsoluteUrl ( url , protocol , host ) {
2615 if ( protocolRelativeRegex . test ( url ) ) {
2716 url = host + url ;
2817 } else if ( ! httpRegex . test ( url ) ) {
@@ -33,9 +22,24 @@ define('fetch/setup', ['exports'], function(self) {
3322 }
3423 url = protocol + '//' + host + url ;
3524 }
36- return abortableFetch . fetch ( url , options ) ;
25+ return url ;
26+ }
27+ /**
28+ * Setup the exported fetch for a given origin so it can handle:
29+ * - protocol-relative URL (//can-be-http-or-https.com/)
30+ * - path-relative URL (/file/under/root)
31+ * @param {String|Object } input
32+ * @param {Object } [options]
33+ */
34+ exports [ 'default' ] = function fetch ( input , options ) {
35+ if ( typeof input === 'object' ) {
36+ input . url = buildAbsoluteUrl ( input . url , protocol , host ) ;
37+ } else {
38+ input = buildAbsoluteUrl ( input , protocol , host ) ;
39+ }
40+ return nodeFetch ( input , options ) ;
3741 } ;
38- exports [ 'Request' ] = abortableFetch . Request ;
42+ exports [ 'Request' ] = nodeFetch . Request ;
3943 exports [ 'Headers' ] = nodeFetch . Headers ;
4044 exports [ 'Response' ] = nodeFetch . Response ;
4145 exports [ 'AbortController' ] = AbortControllerPolyfill . AbortController ;
0 commit comments