mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-04 13:47:33 +08:00
fix: the first function call creates multiple axios instances (#3273)
This commit is contained in:
parent
c894a15d13
commit
49c81f6201
@ -3,13 +3,9 @@ import { getClashInfo } from "./cmds";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { useLockFn } from "ahooks";
|
||||
|
||||
let axiosIns: AxiosInstance = null!;
|
||||
|
||||
/// initialize some information
|
||||
/// enable force update axiosIns
|
||||
export const getAxios = async (force: boolean = false) => {
|
||||
if (axiosIns && !force) return axiosIns;
|
||||
let instancePromise: Promise<AxiosInstance> = null!;
|
||||
|
||||
async function getInstancePromise() {
|
||||
let server = "";
|
||||
let secret = "";
|
||||
|
||||
@ -26,13 +22,22 @@ export const getAxios = async (force: boolean = false) => {
|
||||
if (info?.secret) secret = info?.secret;
|
||||
} catch {}
|
||||
|
||||
axiosIns = axios.create({
|
||||
const axiosIns = axios.create({
|
||||
baseURL: `http://${server}`,
|
||||
headers: secret ? { Authorization: `Bearer ${secret}` } : {},
|
||||
timeout: 15000,
|
||||
});
|
||||
axiosIns.interceptors.response.use((r) => r.data);
|
||||
return axiosIns;
|
||||
}
|
||||
|
||||
/// initialize some information
|
||||
/// enable force update axiosIns
|
||||
export const getAxios = async (force: boolean = false) => {
|
||||
if (!instancePromise || force) {
|
||||
instancePromise = getInstancePromise();
|
||||
}
|
||||
return instancePromise;
|
||||
};
|
||||
|
||||
/// Get Version
|
||||
|
Loading…
x
Reference in New Issue
Block a user