remove superagent

This commit is contained in:
James
2020-01-19 11:32:52 -05:00
parent 721e89de2c
commit e41bbcf84e
2 changed files with 20 additions and 10 deletions

View File

@@ -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 {