From bff39941e2da37db8d971b2dc1b84bce8b1fbbc2 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 23 Jun 2020 13:27:28 +0300 Subject: feat: add auth headers to reqeusts --- src/requests.ts | 16 +++++++++------- 1 file 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) => Promise; +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; -- cgit v1.2.3