Passed
Pull Request — master (#133)
by Mathieu
01:32
created

client/src/utils/axios.js   A

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 29
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 17
mnd 3
bc 3
fnc 3
dl 0
loc 29
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
1
import axios from 'axios';
2
import config from '../../config';
3
4
const client = axios.create({
5
  baseURL: process.browser ? config.API_URL : config.API_URL_SSR
6
});
7
8
const header = token => {
9
  if (!token) {
10
    return;
11
  }
12
13
  return {
14
    headers: {
15
      Authorization: `Bearer ${token}`
16
    }
17
  };
18
};
19
20
export const post = (url, payload, token) => {
21
  return client.post(url, payload, header(token));
22
};
23
24
export const put = (url, payload, token) => {
25
  return client.put(url, payload, header(token));
26
};
27
28
export const del = (url, token) => {
29
  return client.delete(url, header(token));
30
};
31
32
export const get = (url, payload, token) => {
33
  return client.get(url, { ...payload, ...header(token) });
34
};
35