Presupuestador_web/client/src/lib/axios/axiosInstance.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-06-06 11:05:54 +00:00
import axiosClient from "axios";
import { setupInterceptorsTo } from "./setupInterceptors";
// extend the AxiosRequestConfig interface and add two optional options raw and silent. I
// https://dev.to/mperon/axios-error-handling-like-a-boss-333d
declare module "axios" {
export interface AxiosRequestConfig {
raw?: boolean;
silent?: boolean;
}
}
export const defaultAxiosRequestConfig = {
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
Accept: "application/json",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "no-cache",
//'api-key': SERVER_API_KEY,
},
//timeout: 300,
// `onUploadProgress` allows handling of progress events for uploads
// browser only
//onUploadProgress: function (progressEvent) {
// Do whatever you want with the native progress event
//},
// `onDownloadProgress` allows handling of progress events for downloads
// browser only
//onDownloadProgress: function (progressEvent) {
// Do whatever you want with the native progress event
//},
// `cancelToken` specifies a cancel token that can be used to cancel the request
/*cancelToken: new CancelToken(function (cancel) {
}),*/
};
/**
* Creates an initial 'axios' instance with custom settings.
*/
2024-06-09 20:04:46 +00:00
export const createAxiosInstance = () =>
setupInterceptorsTo(axiosClient.create(defaultAxiosRequestConfig));