From a71816e5ef690606ffc430e755b86926a0c291bc Mon Sep 17 00:00:00 2001 From: opptylabs Date: Fri, 30 Jun 2023 15:54:21 +0200 Subject: [PATCH 1/2] new helius rpc url --- src/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index f5f6ee9..109ef75 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,18 +27,17 @@ export default { const upgradeHeader = request.headers.get('Upgrade') if (upgradeHeader || upgradeHeader === 'websocket') { - return await fetch(`https://rpc.helius.xyz/?api-key=${env.HELIUS_API_KEY}`, request) + 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 === '/' ? 'rpc' : 'api'}.helius.xyz${pathname}?api-key=${env.HELIUS_API_KEY}${search ? `&${search.slice(1)}` : ''}`, { + const proxyRequest = new Request(`https://${pathname === '/' ? 'mainnet.helius-rpc.com' : 'api.helius.xyz'}${pathname}?api-key=${env.HELIUS_API_KEY}${search ? `&${search.slice(1)}` : ''}`, { method: request.method, body: payload || null, headers: { 'Content-Type': 'application/json', 'X-Helius-Cloudflare-Proxy': 'true', - ...corsHeaders, } }); From 72bbbc7cf1ff213f411db9c7502bcb9a3e32c438 Mon Sep 17 00:00:00 2001 From: opptylabs Date: Fri, 30 Jun 2023 16:04:19 +0200 Subject: [PATCH 2/2] fix cors in response --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 109ef75..b3f94d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,6 +41,11 @@ export default { } }); - return await fetch(proxyRequest); + return await fetch(proxyRequest).then(res => { + return new Response(res.body, { + status: res.status, + headers: corsHeaders + }); + }); }, };