import Axios, { AxiosResponse } from 'axios'
const service = Axios.create(
  {
    baseURL: 'http://192.168.21.133:3000/'
  }
)
const newsService = Axios.create({
  baseURL: '/proxyFile'
})

const response_interceptor = (res: AxiosResponse<any>) => {
  if (res.status === 200 || res.status === 201) {
    return res.data
  }
  else throw new Error(res.statusText)
}

service.interceptors.response.use(
  (response) => {
    let res = response_interceptor(response);
    return res;
  },
  (err) => {
    return Promise.reject(err);
  }
);

newsService.interceptors.response.use(
  (response) => {
    let res = response_interceptor(response);
    return res;
  },
  (err) => {
    return Promise.reject(err);
  }
);
export {service, newsService} 