From 64b73c5bc1a89a6697f6d757c403cb20eb2f9060 Mon Sep 17 00:00:00 2001 From: vovkman Date: Fri, 10 May 2024 16:22:49 -0700 Subject: [PATCH] u --- src/index.ts | 28 +++++++++++++--------------- wrangler.toml | 13 ++++++++++++- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/index.ts b/src/index.ts index b1b0ed3..b6a4457 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,6 @@ interface Env { export default { async fetch(request: Request, env: Env) { - // If the request is an OPTIONS request, return a 200 response with permissive CORS headers // This is required for the Helius RPC Proxy to work from the browser and arbitrary origins // If you wish to restrict the origins that can access your Helius RPC Proxy, you can do so by @@ -15,47 +14,46 @@ export default { // originated from one of the domains in the `CORS_ALLOW_ORIGIN` environment variable. const supportedDomains = env.CORS_ALLOW_ORIGIN ? env.CORS_ALLOW_ORIGIN.split(',') : undefined; const corsHeaders: Record = { - "Access-Control-Allow-Methods": "GET, HEAD, POST, PUT, OPTIONS", - "Access-Control-Allow-Headers": "*", - } + 'Access-Control-Allow-Methods': 'GET, HEAD, POST, PUT, OPTIONS', + 'Access-Control-Allow-Headers': '*', + }; if (supportedDomains) { - const origin = request.headers.get('Origin') + const origin = request.headers.get('Origin'); if (origin && supportedDomains.includes(origin)) { - corsHeaders['Access-Control-Allow-Origin'] = origin + corsHeaders['Access-Control-Allow-Origin'] = origin; } } else { - corsHeaders['Access-Control-Allow-Origin'] = '*' + corsHeaders['Access-Control-Allow-Origin'] = '*'; } - if (request.method === "OPTIONS") { + if (request.method === 'OPTIONS') { return new Response(null, { status: 200, headers: corsHeaders, }); } - const upgradeHeader = request.headers.get('Upgrade') + 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) + return await fetch(`http://mainnet.dev.lb.helius-internal.com`, request); } - - const { pathname, search } = new URL(request.url) + 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)}` : ''}`, { + const proxyRequest = new Request(`http://mainnet.dev.lb.helius-internal.com`, { method: request.method, body: payload || null, headers: { 'Content-Type': 'application/json', 'X-Helius-Cloudflare-Proxy': 'true', - } + }, }); return await fetch(proxyRequest).then(res => { return new Response(res.body, { status: res.status, - headers: corsHeaders + headers: corsHeaders, }); }); }, diff --git a/wrangler.toml b/wrangler.toml index 2fe4c34..3c17132 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,3 +1,14 @@ -name = "rpc-proxy" # todo +name = "cf-debugging-worker" # todo main = "./src/index.ts" compatibility_date = "2022-05-03" +account_id = "677751811ae9772122dc6f1d03848974" +logpush = true +usage_model = "unbound" +node_compat = true + +routes = [ + { pattern = "cf-debugging.helius-internal.com", custom_domain = true }, +] + +[placement] +mode = "smart" \ No newline at end of file