diff --git a/package.json b/package.json index cab7cf1b9f..8f87ec52f0 100644 --- a/package.json +++ b/package.json @@ -65,8 +65,6 @@ "react-router-dom": "^4.3.1", "redux": "^4.0.4", "sharp": "^0.22.1", - "superagent": "^3.8.3", - "superagent-promise": "^1.1.0", "universal-cookie": "^3.1.0", "url-loader": "^1.0.1", "webpack": "^4.41.0", diff --git a/src/client/api.js b/src/client/api.js index 7994d10597..fa16eb7d6a 100644 --- a/src/client/api.js +++ b/src/client/api.js @@ -1,13 +1,9 @@ import Cookies from 'universal-cookie'; -import superagentPromise from 'superagent-promise'; -import _superagent from 'superagent'; import qs from 'qs'; const cookies = new Cookies(); -const superagent = superagentPromise(_superagent, global.Promise); -const responseBody = res => res.body; -const setJwt = () => { +const setJWT = () => { const jwt = cookies.get('token'); return jwt ? { 'Authorization': `JWT ${jwt}` } : {} }; @@ -15,14 +11,30 @@ const setJwt = () => { const requests = { get: (url, params) => { const query = qs.stringify(params, { addQueryPrefix: true }); - return superagent.get(`${url}${query}`).set(setJwt()).then(responseBody); + return fetch(`${url}${query}`, { + headers: { + ...setJWT() + } + }).then(res => res.body); }, post: (url, body) => - superagent.post(`${url}`, body).set(setJwt()).then(responseBody), + fetch(`${url}`, { + method: 'post', + body, + headers: { + ...setJWT() + }, + }).then(res => res.body), put: (url, body) => - superagent.put(`${url}`, body).set(setJwt()).then(responseBody) + fetch(`${url}`, { + method: 'put', + body, + headers: { + ...setJWT() + }, + }).then(res => res.body), }; export default {