import axios from "axios";
import store from "@/store";
import userAPIs from "@/api/user";

const httpPrefix = "http";

const instance = axios.create({
  baseURL: "/api"
});
//
// const specialUrls = [
//   "/eval",
// ];

instance.interceptors.request.use(
  async (config) => {
    if(config.url.startsWith(httpPrefix)){
      config.baseURL = "";
    }

    // if(specialUrls.indexOf(config.url) !== -1){
    //   const res = await userAPIs.loginAPI({
    //     phone: "17301585267",
    //     password: "SEEC2020",
    //   });
    //   config.headers.authorization = res.data.data.token;
    //   return config;
    // }

    if (store.state.user.token) {
      config.headers.authorization = store.state.user.token;
    } else {
      delete config.headers.authorization;
    }
    return config;
  },
  (error) => {
    console.error(error);
  }
);

// instance.interceptors.response.use((response) => {
//
// });

export {
  instance as axios
};
