From 4bf2a225484e019565d1e8a30d908012cf0c7635 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Mon, 24 Jun 2024 23:25:45 +0700 Subject: [PATCH] feat: add widget api key --- chain-registry | 2 +- env.d.ts | 1 + next.config.js | 4 ++++ src/pages/api/widget/skip/handler.ts | 34 ++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/pages/api/widget/skip/handler.ts diff --git a/chain-registry b/chain-registry index 9063f1ef..017da76e 160000 --- a/chain-registry +++ b/chain-registry @@ -1 +1 @@ -Subproject commit 9063f1eff6624136877529c14972140e4f15297d +Subproject commit 017da76e20562a6b9c8f0e36b51da920aa256d56 diff --git a/env.d.ts b/env.d.ts index 031aeeca..4896de2d 100644 --- a/env.d.ts +++ b/env.d.ts @@ -12,6 +12,7 @@ declare namespace NodeJS { readonly WALLETCONNECT_VERIFY_KEY?: string; readonly WORD_PHRASE_KEY?: string; readonly NEXT_PUBLIC_IS_TESTNET?: boolean; + readonly WIDGET_SKIP_API_KEY?: string; readonly SKIP_API_KEY?: string; readonly ALLOWED_LIST_EDGE_CONFIG?: string; diff --git a/next.config.js b/next.config.js index 643a2445..3ed2aca4 100644 --- a/next.config.js +++ b/next.config.js @@ -35,6 +35,10 @@ let nextConfig = { source: "/api/skip/(.*)", destination: "/api/skip/handler", }, + { + source: "/api/widget/skip/(.*)", + destination: "/api/widget/skip/handler", + }, ], transpilePackages: process.env.NODE_ENV === "test" diff --git a/src/pages/api/widget/skip/handler.ts b/src/pages/api/widget/skip/handler.ts new file mode 100644 index 00000000..d2513738 --- /dev/null +++ b/src/pages/api/widget/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/widget/skip/"; + + const [...args] = req.url!.split(splitter).pop()!.split("/"); + const uri = [API_URL, ...args].join("/"); + const headers = new Headers(); + if (process.env.WIDGET_SKIP_API_KEY) { + headers.set("authorization", process.env.WIDGET_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 }); + } +}