diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-23 13:27:28 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-23 13:27:28 +0300 |
commit | bff39941e2da37db8d971b2dc1b84bce8b1fbbc2 (patch) | |
tree | c4506eae60176a02b80fd816c9d8c51b41a387e7 | |
parent | c96c159ada5d3988fabd9c62dce76170962d73f2 (diff) | |
download | which-ui-bff39941e2da37db8d971b2dc1b84bce8b1fbbc2.tar.gz |
feat: add auth headers to reqeusts
-rw-r--r-- | src/requests.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/requests.ts b/src/requests.ts index 486502d..6446baa 100644 --- a/src/requests.ts +++ b/src/requests.ts @@ -1,10 +1,12 @@ -import axios, { AxiosResponse } from 'axios'; +import axios from 'axios'; -type Request = (url: string, data?: Record<string, unknown>) => Promise<AxiosResponse>; +const requests = axios.create({ + baseURL: 'http://localhost:3030', + headers: { + 'Authorization': localStorage.getItem('token') + } +}); -const baseApiUrl = 'http://localhost:3030'; - -export const get: Request = url => axios.get(baseApiUrl + url); -export const del: Request = url => axios.delete(baseApiUrl + url); -export const post: Request = (url, data) => axios.post(baseApiUrl + url, data); +export const { get, post, put } = requests; +export default requests; |