Skip to content

Commit d692fc5

Browse files
koistyaokendoken
authored andcommitted
Remove isomorphic-fetch in favor of node-fetch + whatwg-fetch (#1339)
1 parent 046fab5 commit d692fc5

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"history": "^4.6.3",
3131
"isomorphic-style-loader": "^2.0.0",
3232
"jsonwebtoken": "^7.4.1",
33-
"node-fetch": "^1.6.3",
33+
"node-fetch": "^1.7.1",
3434
"normalize.css": "^7.0.0",
3535
"passport": "^0.3.2",
3636
"passport-facebook": "^2.1.1",

src/client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* LICENSE.txt file in the root directory of this source tree.
88
*/
99

10+
import 'whatwg-fetch';
1011
import React from 'react';
1112
import ReactDOM from 'react-dom';
1213
import { Router } from 'react-router';
@@ -33,7 +34,7 @@ const context = {
3334
return () => { removeCss.forEach(f => f()); };
3435
},
3536
// Universal HTTP client
36-
fetch: createFetch({
37+
fetch: createFetch(self.fetch, {
3738
baseUrl: window.App.apiUrl,
3839
}),
3940
// Initialize a new Redux store

src/createFetch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/* @flow */
1111

12-
import fetch from 'isomorphic-fetch';
12+
type Fetch = (url: string, options: ?any) => Promise<any>;
1313

1414
type Options = {
1515
baseUrl: string,
@@ -22,7 +22,7 @@ type Options = {
2222
* of boilerplate code in the application.
2323
* https://developer.mozilla.org/docs/Web/API/Fetch_API/Using_Fetch
2424
*/
25-
function createFetch({ baseUrl, cookie }: Options) {
25+
function createFetch(fetch: Fetch, { baseUrl, cookie }: Options) {
2626
// NOTE: Tweak the default options to suite your application needs
2727
const defaults = {
2828
method: 'POST', // handy with GraphQL backends
@@ -35,7 +35,7 @@ function createFetch({ baseUrl, cookie }: Options) {
3535
},
3636
};
3737

38-
return (url, options) => ((url.startsWith('/graphql') || url.startsWith('/api')) ?
38+
return (url: string, options: any) => ((url.startsWith('/graphql') || url.startsWith('/api')) ?
3939
fetch(`${baseUrl}${url}`, {
4040
...defaults,
4141
...options,

src/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import bodyParser from 'body-parser';
1414
import expressJwt, { UnauthorizedError as Jwt401Error } from 'express-jwt';
1515
import expressGraphQL from 'express-graphql';
1616
import jwt from 'jsonwebtoken';
17+
import fetch from 'node-fetch';
1718
import React from 'react';
1819
import { StaticRouter } from 'react-router';
1920
import ReactDOM from 'react-dom/server';
@@ -116,7 +117,7 @@ app.get('*', async (req, res, next) => {
116117
try {
117118
const css = new Set();
118119

119-
const fetch = createFetch({
120+
const fetch = createFetch(fetch, {
120121
baseUrl: config.api.serverUrl,
121122
cookie: req.headers.cookie,
122123
});

yarn.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,8 +2283,8 @@ ejs@^2.5.6:
22832283
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.5.6.tgz#479636bfa3fe3b1debd52087f0acb204b4f19c88"
22842284

22852285
electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.14:
2286-
version "1.3.14"
2287-
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.14.tgz#64af0f9efd3c3c6acd57d71f83b49ca7ee9c4b43"
2286+
version "1.3.15"
2287+
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.15.tgz#08397934891cbcfaebbd18b82a95b5a481138369"
22882288

22892289
elegant-spinner@^1.0.1:
22902290
version "1.0.1"
@@ -3817,7 +3817,7 @@ isobject@^2.0.0:
38173817
dependencies:
38183818
isarray "1.0.0"
38193819

3820-
isomorphic-fetch@^2.1.1, isomorphic-fetch@^2.2.1:
3820+
isomorphic-fetch@^2.1.1:
38213821
version "2.2.1"
38223822
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
38233823
dependencies:
@@ -3902,8 +3902,8 @@ js-base64@^2.1.9:
39023902
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.1.9.tgz#f0e80ae039a4bd654b5f281fc93f04a914a7fcce"
39033903

39043904
js-tokens@^3.0.0:
3905-
version "3.0.1"
3906-
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"
3905+
version "3.0.2"
3906+
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
39073907

39083908
js-yaml@^3.4.3, js-yaml@^3.4.6, js-yaml@^3.5.1:
39093909
version "3.8.4"
@@ -4721,7 +4721,7 @@ [email protected]:
47214721
version "0.6.1"
47224722
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
47234723

4724-
node-fetch@^1.0.1:
4724+
node-fetch@^1.0.1, node-fetch@^1.7.1:
47254725
version "1.7.1"
47264726
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.1.tgz#899cb3d0a3c92f952c47f1b876f4c8aeabd400d5"
47274727
dependencies:
@@ -7531,7 +7531,7 @@ weinre@^2.0.0-pre-I0Z7U9OV:
75317531
nopt "3.0.x"
75327532
underscore "1.7.x"
75337533

7534-
whatwg-fetch@>=0.10.0:
7534+
whatwg-fetch@>=0.10.0, whatwg-fetch@^2.0.3:
75357535
version "2.0.3"
75367536
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz#9c84ec2dcf68187ff00bc64e1274b442176e1c84"
75377537

0 commit comments

Comments
 (0)