react-redux-express
Version:
React fullstack generator with express,redux, and some components.
28 lines (21 loc) • 555 B
JavaScript
/**
* Created by Zhengfeng Yao on 16/8/24.
*/
import Promise from 'bluebird';
import fetch, { Request, Headers, Response } from 'node-fetch';
import { host } from '../../config';
fetch.Promise = Promise;
Response.Promise = Promise;
function localUrl(url) {
if (url.startsWith('//')) {
return `https:${url}`;
}
if (url.startsWith('http')) {
return url;
}
return `http://${host}${url}`;
}
function localFetch(url, options) {
return fetch(localUrl(url), options);
}
export { localFetch as default, Request, Headers, Response };