/*
 * @Author: Kane
 * @Date: 2023-02-28 17:47:22
 * @LastEditors: Kane
 * @FilePath: /task_schedule/src/utils/api/request.ts
 * @Description:
 *
 * Copyright (c) ${2022} by Kane, All Rights Reserved.
 */

import axios, { type AxiosInstance } from "axios";

const service: AxiosInstance = axios.create(
    {
        baseURL: "",
        timeout: 30000,
    }
);

// 请求拦截
service.interceptors.request.use(
    /**
     * 请求拦截器，在此加入token
     * @param config 配置对象,在此加入token。
     * @returns 返回修改完的配置对象
     */
    ( config ) =>
    {
        config.headers.token = "123";

        return config;
    },
    async ( error ) =>
    {
        console.log( error );

        return await Promise.reject( error );
    }
);

// 响应拦截
service.interceptors.response.use(
    ( response ) =>
    {
        return response;
    },
    async ( error ) =>
    {
        return await Promise.reject( error );
    }
);

export { service };
