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;