Skip to content

Commit

Permalink
Merge pull request helius-labs#3 from opptylabs/main
Browse files Browse the repository at this point in the history
Support new Helius RPC URL
  • Loading branch information
owenventer authored Jul 4, 2023
2 parents b5fc981 + 345c237 commit 4a4a73c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}` : ''}`, {
Expand All @@ -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
});
});
},
};

0 comments on commit 4a4a73c

Please sign in to comment.