From 756f4399177fc1d9862136bc72e80d6ccfe53aa8 Mon Sep 17 00:00:00 2001 From: Griko Nibras Date: Tue, 13 Feb 2024 08:36:22 +0700 Subject: [PATCH] fix: borked proxy Signed-off-by: Griko Nibras --- src/utils/api.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/api.ts b/src/utils/api.ts index a214456e..8bd28b62 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -5,7 +5,13 @@ import { type FallbackEndpointFn, getWhitelabelEndpoint } from "@/config/endpoin export function createProxyHandler(type: "api" | "rpc", fallbackFn?: FallbackEndpointFn) { return async function handler(req: NextRequest) { try { - const [chainID, ...args] = req.url.split(`/api/${type}/`).pop()!.split("/"); + const splitter = (() => { + if (type === "api") return "/api/rest/"; + if (type === "rpc") return "/api/rpc/"; + throw new Error(`createProxyHandler error: unknown handler type '${type}'`); + })(); + + const [chainID, ...args] = req.url.split(splitter).pop()!.split("/"); let data = getWhitelabelEndpoint(chainID, type); fallbackFn && (data ??= await fallbackFn(chainID));