Skip to content

Commit 2d56780

Browse files
committed
use axios instead of superagent
1 parent 27b90d7 commit 2d56780

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@
178178
"serve-favicon": "^2.3.2",
179179
"socket.io": "^2.0.1",
180180
"socket.io-client": "^2.0.1",
181-
"superagent": "^3.4.4",
182181
"verror": "^1.10.0"
183182
},
184183
"devDependencies": {

src/app.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import rest from 'feathers-rest/client';
66
import socketio from 'feathers-socketio/client';
77
import authentication from 'feathers-authentication-client';
88
import io from 'socket.io-client';
9-
import superagent from 'superagent';
9+
import axios from 'axios';
1010
import config from './config';
1111

1212
const storage = __SERVER__ ? null : require('localforage');
@@ -23,17 +23,19 @@ export const socket = io('', { path: host('/ws'), autoConnect: false });
2323

2424
export function createApp(req) {
2525
if (req === 'rest') {
26-
return configureApp(rest(host('/api')).superagent(superagent));
26+
return configureApp(rest(host('/api')).axios(axios));
2727
}
2828

2929
if (__SERVER__ && req) {
3030
const app = configureApp(
31-
rest(host('/api')).superagent(superagent, {
32-
headers: {
33-
Cookie: req.get('cookie'),
34-
authorization: req.header('authorization') || ''
35-
}
36-
})
31+
rest(host('/api')).axios(
32+
axios.create({
33+
headers: {
34+
Cookie: req.get('cookie'),
35+
authorization: req.header('authorization') || ''
36+
}
37+
})
38+
)
3739
);
3840

3941
const accessToken = req.header('authorization') || (req.cookies && req.cookies['feathers-jwt']);

src/helpers/apiClient.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ export default function apiClient(req) {
66
baseURL: __SERVER__ ? `http://${config.apiHost}:${config.apiPort}` : '/api'
77
});
88

9-
instance.setJwtToken = token => {
10-
instance.defaults.headers.common.Authorization = token;
9+
let token;
10+
11+
instance.setJwtToken = newToken => {
12+
token = newToken;
1113
};
1214

1315
instance.interceptors.request.use(
1416
conf => {
15-
if (__SERVER__ && req.get('cookie')) {
16-
conf.headers.Cookie = req.get('cookie');
17+
if (__SERVER__) {
18+
if (req.header('cookie')) {
19+
conf.headers.Cookie = req.header('cookie');
20+
}
21+
if (req.header('authorization')) {
22+
conf.headers.authorization = token || req.header('authorization') || '';
23+
}
1724
}
1825
return conf;
1926
},

src/redux/modules/survey.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ export default function reducer(state = initialState /* , action = {} */) {
1111
export function isValidEmail(data) {
1212
return {
1313
types: [IS_VALID, IS_VALID_SUCCESS, IS_VALID_FAIL],
14-
promise: ({ client }) =>
15-
client.post('/survey/isValid', {
16-
data
17-
})
14+
promise: ({ client }) => client.post('/survey/isValid', data)
1815
};
1916
}

src/redux/modules/widgets.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ export function save(widget) {
100100
return {
101101
types: [SAVE, SAVE_SUCCESS, SAVE_FAIL],
102102
id: widget.id,
103-
promise: ({ client }) =>
104-
client.post('/widget/update', {
105-
data: widget
106-
})
103+
promise: ({ client }) => client.post('/widget/update', widget)
107104
};
108105
}
109106

webpack/vendor.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module.exports = {
6262

6363
// </babel-runtime>
6464

65+
'axios',
6566
'multireducer',
6667
'react',
6768
'react-bootstrap',
@@ -77,8 +78,7 @@ module.exports = {
7778
'redux-connect',
7879
'redux-form',
7980
'serialize-javascript',
80-
'socket.io-client',
81-
'superagent'
81+
'socket.io-client'
8282
]
8383
},
8484

0 commit comments

Comments
 (0)