Passed
Pull Request — master (#133)
by Mathieu
01:47
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
3
const client = axios.create({
4
  baseURL: process.browser ? config.API_URL : config.API_URL_SSR
5
});
6
7
const header = (token) => {
8
  if (!token) {
9
    return;
10
  }
11
12
  return {
13
    headers: {
14
      Authorization: `Bearer ${token}`
15
    }
16
  };
17
};
18
19
export const post = (url, payload, token) => {
20
  return client.post(url, payload, header(token));
21
};
22
23
export const put = (url, payload, token) => {
24
  return client.put(url, payload, header(token));
25
};
26
27
export const del = (url, token) => {
28
  return client.delete(url, header(token));
29
};
30
31
export const get = (url, payload, token) => {
32
  return client.get(url, {...payload, ...header(token)});
33
};
34