aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-23 13:27:28 +0300
committereug-vs <eug-vs@keemail.me>2020-06-23 13:27:28 +0300
commitbff39941e2da37db8d971b2dc1b84bce8b1fbbc2 (patch)
treec4506eae60176a02b80fd816c9d8c51b41a387e7
parentc96c159ada5d3988fabd9c62dce76170962d73f2 (diff)
downloadwhich-ui-bff39941e2da37db8d971b2dc1b84bce8b1fbbc2.tar.gz
feat: add auth headers to reqeusts
-rw-r--r--src/requests.ts16
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;