Skip to content

Commit

Permalink
Merge pull request #170 from skip-mev/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
Griko Nibras authored Feb 13, 2024
2 parents 5d46dd0 + 208df01 commit 1e3a731
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 1e3a731

Please sign in to comment.