Skip to content

Commit

Permalink
feat: add widget api key
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki committed Jun 24, 2024
1 parent 80259e3 commit 4bf2a22
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 34 additions & 0 deletions src/pages/api/widget/skip/handler.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
}

0 comments on commit 4bf2a22

Please sign in to comment.