You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
998 B
42 lines
998 B
1 year ago
|
import axios from 'axios';
|
||
|
|
||
|
export const API_HOST = `${window.location.protocol}//${window.location.host}/`;
|
||
|
export const API_PROXY_PREFIX = 'api/plugin-proxy/corpglory-dataexporter-app';
|
||
|
export const API_PATH_PREFIX = '/api';
|
||
|
|
||
|
const instance = axios.create();
|
||
|
|
||
|
instance.interceptors.request.use(function (config) {
|
||
|
config.validateStatus = (status) => {
|
||
|
return status >= 200 && status < 300; // default
|
||
|
};
|
||
|
|
||
|
return {
|
||
|
...config,
|
||
|
};
|
||
|
});
|
||
|
|
||
|
interface RequestConfig {
|
||
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
|
||
|
params?: any;
|
||
|
data?: any;
|
||
|
withCredentials?: boolean;
|
||
|
validateStatus?: (status: number) => boolean;
|
||
|
}
|
||
|
|
||
1 year ago
|
export const queryApi = async <RT = any>(path: string, config: RequestConfig) => {
|
||
1 year ago
|
const { method = 'GET', params, data, validateStatus } = config;
|
||
|
|
||
|
const url = `${API_PROXY_PREFIX}${API_PATH_PREFIX}${path}`;
|
||
|
|
||
|
const response = await instance({
|
||
|
method,
|
||
|
url,
|
||
|
params,
|
||
|
data,
|
||
|
validateStatus,
|
||
|
});
|
||
|
|
||
|
return response.data as RT;
|
||
|
};
|