@king-one/axios-extend
Advanced tools
Comparing version
# @king-one/axios-extend | ||
## 1.0.6 | ||
### Patch Changes | ||
- feat:增加请求参数接口 | ||
## 1.0.5 | ||
@@ -4,0 +10,0 @@ |
@@ -5,22 +5,26 @@ "use strict"; | ||
let prefixPromise = null; | ||
const { getPrefix, prefixCall, ignoreUrls = [] } = options; | ||
const { getPrefix, prefixCall } = options; | ||
axios.interceptors.request.use(async (config) => { | ||
let prefix = getPrefix(); | ||
if (!prefix && !ignoreUrls.includes(config.url || "")) { | ||
if (!prefixPromise) { | ||
const result = prefixCall(); | ||
prefixPromise = result instanceof Promise ? result : Promise.resolve(); | ||
prefixPromise.finally(() => { | ||
prefixPromise = null; | ||
}); | ||
if (!config.isPrefix) { | ||
return config; | ||
} else { | ||
let prefix = getPrefix(); | ||
if (!prefix) { | ||
if (!prefixPromise) { | ||
const result = prefixCall(); | ||
prefixPromise = result instanceof Promise ? result : Promise.resolve(); | ||
prefixPromise.finally(() => { | ||
prefixPromise = null; | ||
}); | ||
} | ||
await prefixPromise; | ||
prefix = getPrefix(); | ||
} | ||
await prefixPromise; | ||
prefix = getPrefix(); | ||
if (prefix && config.url) { | ||
config.url = prefix.startsWith("/") ? `${prefix}${config.url}` : `/${prefix}${config.url}`; | ||
} | ||
return config; | ||
} | ||
if (prefix && config.url) { | ||
config.url = prefix.startsWith("/") ? `${prefix}${config.url}` : `/${prefix}${config.url}`; | ||
} | ||
return config; | ||
}); | ||
} | ||
exports.axiosPrefix = axiosPrefix; |
@@ -1,7 +0,9 @@ | ||
import { AxiosInstance } from 'axios'; | ||
import { AxiosInstance, InternalAxiosRequestConfig } from 'axios'; | ||
export interface AxiosPrefixOpstions { | ||
getPrefix: () => string | undefined | null; | ||
prefixCall: () => void | Promise<void>; | ||
ignoreUrls?: string[]; | ||
} | ||
export interface PrefixAxiosRequestConfig extends InternalAxiosRequestConfig { | ||
isPrefix?: boolean; | ||
} | ||
export declare function axiosPrefix(axios: AxiosInstance, options: AxiosPrefixOpstions): void; |
{ | ||
"name": "@king-one/axios-extend", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "", |
Sorry, the diff of this file is not supported yet
4068
6.6%87
12.99%