From dd0c03b8a06983d47b71573f12f719b92942d978 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Sat, 27 Apr 2024 16:44:28 +0700 Subject: [PATCH 1/2] proxy skip api url and set header authorization key --- env.d.ts | 2 ++ next.config.js | 4 ++++ src/pages/api/skip/handler.ts | 34 ++++++++++++++++++++++++++++++++++ src/solve/context.tsx | 4 ++-- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/pages/api/skip/handler.ts diff --git a/env.d.ts b/env.d.ts index 1355c2e2..bf040eaa 100644 --- a/env.d.ts +++ b/env.d.ts @@ -13,6 +13,8 @@ declare namespace NodeJS { readonly WALLETCONNECT_VERIFY_KEY?: string; readonly WORD_PHRASE_KEY?: string; readonly NEXT_PUBLIC_IS_TESTNET?: boolean; + + readonly SKIP_API_KEY?: string; } } diff --git a/next.config.js b/next.config.js index 2f1338fa..643a2445 100644 --- a/next.config.js +++ b/next.config.js @@ -31,6 +31,10 @@ let nextConfig = { source: "/api/rpc/(.*)", destination: "/api/rpc/handler", }, + { + source: "/api/skip/(.*)", + destination: "/api/skip/handler", + }, ], transpilePackages: process.env.NODE_ENV === "test" diff --git a/src/pages/api/skip/handler.ts b/src/pages/api/skip/handler.ts new file mode 100644 index 00000000..63389689 --- /dev/null +++ b/src/pages/api/skip/handler.ts @@ -0,0 +1,34 @@ +// Next.js API route support: https://nextjs.org/docs/api-routes/introduction +import type { NextApiRequest } from "next"; +import { PageConfig } from "next"; + +import { API_URL } from "@/constants/api"; + +export const config: PageConfig = { + api: { + externalResolver: true, + bodyParser: false, + }, + runtime: "edge", +}; + +export default async function handler(req: NextApiRequest) { + try { + const splitter = "/api/skip/"; + + const [...args] = req.url!.split(splitter).pop()!.split("/"); + const uri = [API_URL, ...args].join("/"); + const headers = new Headers(); + if (process.env.SKIP_API_KEY) { + headers.set("authorization", process.env.SKIP_API_KEY); + } + return fetch(uri, { + body: req.body, + method: req.method, + headers, + }); + } catch (error) { + const data = JSON.stringify({ error }); + return new Response(data, { status: 500 }); + } +} diff --git a/src/solve/context.tsx b/src/solve/context.tsx index 3cebc87e..e835608c 100644 --- a/src/solve/context.tsx +++ b/src/solve/context.tsx @@ -6,7 +6,7 @@ import { createContext, ReactNode } from "react"; import { WalletClient } from "viem"; import { chainIdToName } from "@/chains/types"; -import { API_URL, appUrl } from "@/constants/api"; +import { appUrl } from "@/constants/api"; import { trackWallet } from "@/context/track-wallet"; import { config } from "@/lib/wagmi"; import { gracefullyConnect, isWalletClientUsingLedger } from "@/utils/wallet"; @@ -19,7 +19,7 @@ export function SkipProvider({ children }: { children: ReactNode }) { const skipClient = new SkipRouter({ clientID: process.env.NEXT_PUBLIC_CLIENT_ID, - apiURL: API_URL, + apiURL: `${appUrl}/api/skip`, getCosmosSigner: async (chainID) => { const chainName = chainIdToName[chainID]; if (!chainName) { From 58c0bcea4ee90720e5154fc30deb27463b98fb44 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Wed, 1 May 2024 04:52:12 +0700 Subject: [PATCH 2/2] sync registry --- chain-registry | 2 +- initia-registry | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chain-registry b/chain-registry index 1b1b932d..03ac19b1 160000 --- a/chain-registry +++ b/chain-registry @@ -1 +1 @@ -Subproject commit 1b1b932d410ed859befec217d02c971407023c34 +Subproject commit 03ac19b14446e72af30453d0f023ba5be8014e1d diff --git a/initia-registry b/initia-registry index 0d845023..4352b12d 160000 --- a/initia-registry +++ b/initia-registry @@ -1 +1 @@ -Subproject commit 0d845023a05055841ab92c3991ed237b3023ecf4 +Subproject commit 4352b12da33fac2bceb14e90e06007e2c4194951