Updated axios request object, added minio
This commit is contained in:
@@ -1,15 +1,33 @@
|
||||
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
|
||||
const serviceHost = process.env.SERVICE_HOST || 'http://localhost';
|
||||
const servicePort = process.env.SERVICE_PORT || 5000;
|
||||
|
||||
function createAxiosClient(): AxiosInstance {
|
||||
const axiosClient = axios.create({
|
||||
baseURL: `${serviceHost}:${servicePort}`
|
||||
});
|
||||
|
||||
axiosClient.interceptors.request.use(
|
||||
(request) => {
|
||||
request.withCredentials = true;
|
||||
return request;
|
||||
},
|
||||
(error) => {
|
||||
console.error(error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
return axiosClient;
|
||||
}
|
||||
|
||||
const axiosClient = createAxiosClient();
|
||||
|
||||
export async function getRequest(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<any>
|
||||
): Promise<AxiosResponse<any, any> | undefined> {
|
||||
const response = await axios
|
||||
.get(`${serviceHost}:${servicePort}/${url}`, config)
|
||||
.catch((error) => console.error(error));
|
||||
const response = await axiosClient.get(`/${url}`, config);
|
||||
return response || undefined;
|
||||
}
|
||||
|
||||
@@ -18,9 +36,7 @@ export async function postRequest(
|
||||
data?: any,
|
||||
config?: AxiosRequestConfig<any>
|
||||
): Promise<AxiosResponse<any, any> | undefined> {
|
||||
const response = await axios
|
||||
.post(`${serviceHost}:${servicePort}/${url}`, data, config)
|
||||
.catch((error) => console.error(error));
|
||||
const response = await axiosClient.post(`/${url}`, data, config);
|
||||
return response || undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user