diff --git a/src/index.ts b/src/index.ts index 2847bf0..b1b0ed3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,10 +35,12 @@ export default { } const upgradeHeader = request.headers.get('Upgrade') + if (upgradeHeader || upgradeHeader === 'websocket') { return await fetch(`https://mainnet.helius-rpc.com/?api-key=${env.HELIUS_API_KEY}`, request) } + const { pathname, search } = new URL(request.url) const payload = await request.text(); const proxyRequest = new Request(`https://${pathname === '/' ? 'mainnet.helius-rpc.com' : 'api.helius.xyz'}${pathname}?api-key=${env.HELIUS_API_KEY}${search ? `&${search.slice(1)}` : ''}`, { @@ -47,10 +49,14 @@ export default { headers: { 'Content-Type': 'application/json', 'X-Helius-Cloudflare-Proxy': 'true', - ...corsHeaders, } }); - return await fetch(proxyRequest); + return await fetch(proxyRequest).then(res => { + return new Response(res.body, { + status: res.status, + headers: corsHeaders + }); + }); }, };