diff --git a/src/mocks/handlers/external.js b/src/mocks/handlers/external.js new file mode 100644 index 00000000..6b68fd8e --- /dev/null +++ b/src/mocks/handlers/external.js @@ -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( + // 'Avatar', + // { + // headers: { 'Content-Type': 'image/svg+xml' } + // } + // ); + // }), +]; diff --git a/src/mocks/handlers/index.js b/src/mocks/handlers/index.js index 530ac1b8..41699941 100644 --- a/src/mocks/handlers/index.js +++ b/src/mocks/handlers/index.js @@ -14,6 +14,7 @@ import { marketHandlers } from './market'; import { financialHandlers } from './financial'; import { limitAnalyseHandlers } from './limitAnalyse'; import { posthogHandlers } from './posthog'; +import { externalHandlers } from './external'; // 可以在这里添加更多的 handlers // import { userHandlers } from './user'; @@ -32,5 +33,6 @@ export const handlers = [ ...financialHandlers, ...limitAnalyseHandlers, ...posthogHandlers, + ...externalHandlers, // ...userHandlers, ]; diff --git a/src/mocks/handlers/posthog.js b/src/mocks/handlers/posthog.js index ded90097..ac1fc2d2 100644 --- a/src/mocks/handlers/posthog.js +++ b/src/mocks/handlers/posthog.js @@ -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 } + ); + } + }), ];