mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-17 16:56:38 +08:00
28 lines
679 B
TypeScript
28 lines
679 B
TypeScript
import axios from "axios";
|
|
import tokenHandler from "./token";
|
|
|
|
const { _tokenData, refreshToken, setCurRequest } = tokenHandler();
|
|
|
|
const createInstance = (baseURL: string = (import.meta as any).env.VITE_PROXY_BASE_URL) => {
|
|
|
|
const instance = axios.create({
|
|
baseURL,
|
|
timeout: 10000,
|
|
withCredentials: true,
|
|
});
|
|
|
|
instance.interceptors.request.use((config) => {
|
|
if (config.url !== _tokenData.get("lastRequest")) {
|
|
refreshToken();
|
|
}
|
|
if (config.method === "post") {
|
|
setCurRequest(config.url);
|
|
config.headers["request-id"] = _tokenData.get("__token");
|
|
}
|
|
return config;
|
|
});
|
|
|
|
return instance;
|
|
}
|
|
|
|
export default createInstance; |