import axios, { AxiosRequestConfig } from 'axios'; import { FlclAxiosMiddleware } from './types'; import { MyGlobal as app } from './globals'; import './utilities/axiosInterceptors' const injectHeaders = (headers: any) => { return { 'Authorization': app.bearerToken, 'id_token': app.idToken, ...headers } } let axiosMiddleware: FlclAxiosMiddleware = { get: (urlPath: string, config?: AxiosRequestConfig) => { let headers = injectHeaders(config?.headers); return axios.get(urlPath, { ...config, headers }); }, put: (urlPath: string, data: any, config?: AxiosRequestConfig) => { let headers = injectHeaders(config?.headers); return axios.put(urlPath, data, { ...config, headers }); }, post: (urlPath: string, data?: any, config?: AxiosRequestConfig) => { let headers = injectHeaders(config?.headers); return axios.post(urlPath, data, { ...config, headers: { ...headers, 'Content-Type': 'application/json' } }); }, delete: (urlPath: string, config?: AxiosRequestConfig) => { let headers = injectHeaders(config?.headers); return axios.delete(urlPath, { ...config, headers }); }, } export default axiosMiddleware;