in packages-fetcher/console-fetcher-interceptor-req-mock/src/intercept/create-interceptor-request.ts [19:62]
export default function createInterceptorRequest({
one = {},
others = []
}: IMockOptions = {}): FetcherFnInterceptRequest {
return (fetcherConfig: FetcherConfig): FetcherInterceptRequestReturn => {
// 这个包不应该被打包到应用,而只应该在 demo 中使用,若有**笨蛋🥚**很认真地把它放到项目代码里边...也不要对线上功能产生干扰
// 同时,如果指定了 urlBase 的...忽略
if (!CONF_ENV.ENV_IS_DEV || fetcherConfig.urlBase) {
return;
}
for (let i = 0; i < others.length; i++) {
const {
id,
check
} = others[i]!; // eslint-disable-line @typescript-eslint/no-non-null-assertion
const checkResult = check(fetcherConfig);
if (checkResult === true) {
return {
urlBase: `${MOCK_PREFIX}/${id}`
};
}
if (checkResult) {
return {
url: checkResult,
urlBase: `${MOCK_PREFIX}/${id}`
};
}
}
if (fetcherConfig.url && REG_ONE_API.test(fetcherConfig.url)) {
const product = (fetcherConfig.body as IBodyWithProduct | undefined)?.product;
return product ? {
url: `${MOCK_PREFIX}/oneconsole/data/${RegExp.$1 ? 'multiApi' : 'api'}.json`,
body: {
product: one[product] || product
}
} : undefined;
}
};
}