import { createAlova } from 'alova';

import axios from 'axios'
const alovaRequest = createAlova({
  statesHook: null,
  baseURL:'http://39.104.123.254:7014/',
  // requestAdapter:axiosAdapter(),
  // headers: {
  //   'Content-Type': 'application/json',
  //   'sid':'TsYnqw90rIPMDaatzfgKO7FT6NzfXULn9FcQr6FCEesPC5izpYoGeTfDALDLKaTim/GS1SaT3tbGdsrSr3kSsftY5FOlVOqBF2AB3jmis4az5wSw9MSZ9UDrGQxz7KUWjmwsvxn13tQmVfLLvylmUmawx70Toh3LTuyzHl+re7J0UX3zCjpNZS/cQ0EExYH4d8kjRlNEmcNr/IjyXKEWztvO2GEaouDetAEhdZDqDrLx4iH1XkmJhYb84A3K8C9pV1sBF7HUp0m0ta/1Dsb89T//uOYwWeUqeRGyFFVBlOLz6TyrK8f/Bpj4YOCOz4VbfsfSTZfpES+IbLjsdvPwLQ=='
  // },
  beforeRequest(method){
    console.log(method)
    method.config.headers.sid = 'TsYnqw90rIPMDaatzfgKO7FT6NzfXULn9FcQr6FCEesPC5izpYoGeTfDALDLKaTim/GS1SaT3tbGdsrSr3kSsftY5FOlVOqBF2AB3jmis4az5wSw9MSZ9UDrGQxz7KUWjmwsvxn13tQmVfLLvylmUmawx70Toh3LTuyzHl+re7J0UX3zCjpNZS/cQ0EExYH4d8kjRlNEmcNr/IjyXKEWztvO2GEaouDetAEhdZDqDrLx4iH1XkmJhYb84A3K8C9pV1sBF7HUp0m0ta/1Dsb89T//uOYwWeUqeRGyFFVBlOLz6TyrK8f/Bpj4YOCOz4VbfsfSTZfpES+IbLjsdvPwLQ==';
  },
  responded: {
    // 请求成功的拦截器
    // 当使用 `alova/fetch` 请求适配器时，第一个参数接收Response对象
    // 第二个参数为当前请求的method实例，你可以用它同步请求前后的配置信息
    onSuccess: async (response, method) => {
      // if (response.status >= 400) {
      //   throw new Error(response.statusText);
      // }
      console.log(response)
      const json = await response.json();
      // if (json.code !== 200) {
      //   // 抛出错误或返回reject状态的Promise实例时，此请求将抛出错误
      //   throw new Error(json.message);
      // }

      // 解析的响应数据将传给method实例的transform钩子函数，这些函数将在后续讲解
      return json.data;
    }
  }
})

export default alovaRequest
