feat: 添加mock数据
This commit is contained in:
25
src/mocks/handlers/external.js
Normal file
25
src/mocks/handlers/external.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// src/mocks/handlers/external.js
|
||||||
|
// 外部服务 Mock Handler(允许通过)
|
||||||
|
|
||||||
|
import { http, passthrough } from 'msw';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部服务处理器
|
||||||
|
* 对于外部服务(如头像、CDN等),使用 passthrough 让请求正常发送到真实服务器
|
||||||
|
*/
|
||||||
|
export const externalHandlers = [
|
||||||
|
// Pravatar 头像服务 - 允许通过到真实服务
|
||||||
|
http.get('https://i.pravatar.cc/*', async () => {
|
||||||
|
return passthrough();
|
||||||
|
}),
|
||||||
|
|
||||||
|
// 如果需要 mock 头像,也可以返回一个占位图片
|
||||||
|
// http.get('https://i.pravatar.cc/*', async () => {
|
||||||
|
// return HttpResponse.text(
|
||||||
|
// '<svg width="150" height="150" xmlns="http://www.w3.org/2000/svg"><rect width="150" height="150" fill="#ddd"/><text x="50%" y="50%" text-anchor="middle" dy=".3em" fill="#999">Avatar</text></svg>',
|
||||||
|
// {
|
||||||
|
// headers: { 'Content-Type': 'image/svg+xml' }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
// }),
|
||||||
|
];
|
||||||
@@ -14,6 +14,7 @@ import { marketHandlers } from './market';
|
|||||||
import { financialHandlers } from './financial';
|
import { financialHandlers } from './financial';
|
||||||
import { limitAnalyseHandlers } from './limitAnalyse';
|
import { limitAnalyseHandlers } from './limitAnalyse';
|
||||||
import { posthogHandlers } from './posthog';
|
import { posthogHandlers } from './posthog';
|
||||||
|
import { externalHandlers } from './external';
|
||||||
|
|
||||||
// 可以在这里添加更多的 handlers
|
// 可以在这里添加更多的 handlers
|
||||||
// import { userHandlers } from './user';
|
// import { userHandlers } from './user';
|
||||||
@@ -32,5 +33,6 @@ export const handlers = [
|
|||||||
...financialHandlers,
|
...financialHandlers,
|
||||||
...limitAnalyseHandlers,
|
...limitAnalyseHandlers,
|
||||||
...posthogHandlers,
|
...posthogHandlers,
|
||||||
|
...externalHandlers,
|
||||||
// ...userHandlers,
|
// ...userHandlers,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -108,4 +108,25 @@ export const posthogHandlers = [
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// PostHog feature flags 接口(特性标志查询)
|
||||||
|
http.post('https://us.i.posthog.com/flags/', async ({ request }) => {
|
||||||
|
try {
|
||||||
|
if (process.env.NODE_ENV === 'development' && process.env.REACT_APP_LOG_POSTHOG === 'true') {
|
||||||
|
console.log('[Mock] PostHog feature flags 请求:', request.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回空的特性标志
|
||||||
|
return HttpResponse.json({
|
||||||
|
featureFlags: {},
|
||||||
|
featureFlagPayloads: {},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Mock] PostHog flags handler error:', error);
|
||||||
|
return HttpResponse.json(
|
||||||
|
{ featureFlags: {}, featureFlagPayloads: {} },
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user