import axios from 'axios';
import { useUserStore } from '@/stores';
const axiosInstance = axios.create({
  baseURL: 'http://wzpmc.cn:18080/'
});
// 自动添加token到请求中.
axiosInstance.interceptors.request.use((config) => {
  const userStore = useUserStore();
  config.headers.setAuthorization(userStore.token, false);
  return config;
});
// 自动获取响应中的token.
axiosInstance.interceptors.response.use((response) => {
  const userStore = useUserStore();
  const authorization = response.headers['set-authorization'] as string | undefined;
  if (authorization !== undefined) {
    userStore.token = authorization;
  }
  return response;
});
export default axiosInstance;
