remove superagent
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user