From 6c660ec591af0d039a85cb3faa61f97b41723518 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 25 Jul 2024 10:50:50 +0800 Subject: [PATCH] fix(telemetry): proxy logic --- packages/telemetry/src/index.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/telemetry/src/index.ts b/packages/telemetry/src/index.ts index 70581ef..5f7997f 100644 --- a/packages/telemetry/src/index.ts +++ b/packages/telemetry/src/index.ts @@ -6,8 +6,21 @@ export default { console.log(request.headers.get('Origin')); return new Response('Method Not Allowed', { status: 405 }); } - headers.set('Host', 'api-eu.mixpanel.com'); - const res = await fetch(request, { + if (request.method === 'OPTIONS') { + return new Response(null, { + status: 204, + headers: { + 'Access-Control-Allow-Origin': request.headers.get('Origin') ?? '*', + 'Access-Control-Allow-Methods': 'POST, OPTIONS', + 'Access-Control-Allow-Headers': '*', + }, + }); + } + headers.set('Host', 'api-js.mixpanel.com'); + const url = new URL(request.url); + url.host = 'api-js.mixpanel.com'; + const req = new Request(url, request); + const res = await fetch(req, { headers, }); return res;