fetch.server.js (771B)
1 /** 2 * React Starter Kit (https://www.reactstarterkit.com/) 3 * 4 * Copyright © 2014-present Kriasoft, LLC. All rights reserved. 5 * 6 * This source code is licensed under the MIT license found in the 7 * LICENSE.txt file in the root directory of this source tree. 8 */ 9 10 import Promise from 'bluebird'; 11 import fetch, { Request, Headers, Response } from 'node-fetch'; 12 import { host } from '../../config'; 13 14 fetch.Promise = Promise; 15 Response.Promise = Promise; 16 17 function localUrl(url) { 18 if (url.startsWith('//')) { 19 return `https:${url}`; 20 } 21 22 if (url.startsWith('http')) { 23 return url; 24 } 25 26 return `http://${host}${url}`; 27 } 28 29 function localFetch(url, options) { 30 return fetch(localUrl(url), options); 31 } 32 33 export { localFetch as default, Request, Headers, Response };