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.
41 lines
1001 B
41 lines
1001 B
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; |
|
} |
|
|
|
export const makeRequest = async <RT = any>(path: string, config: RequestConfig) => { |
|
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; |
|
};
|
|
|