aboutsummaryrefslogtreecommitdiff
path: root/src/requests.ts
blob: 0af80dc35d9d79cc46666d2622b0006abeb17364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import axios from 'axios';
import _ from 'lodash';

const baseURL = process.env.NODE_ENV === 'production'
  ? 'https://which-api.herokuapp.com'
  : 'http://localhost:3030';

const headers = ['Access-Control-Allow-Origin', '*'];
const requests = axios.create({ baseURL, headers });

requests.interceptors.request.use(config => {
  const token = localStorage.getItem('token');
  return _.set(config, 'headers.Authorization', token);
});

export const {
  get, post, put, patch
} = requests;
export default requests;