From 2c9247a965a4bb36c5616f99d987534bb5c9a33c Mon Sep 17 00:00:00 2001 From: devinxl Date: Tue, 3 Dec 2024 15:47:30 +0800 Subject: [PATCH] feat(dcellar-web-ui): add proxy for bnb price api --- apps/dcellar-web-ui/src/facade/common.ts | 2 +- .../src/pages/api/bnb_price/index.tsx | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 apps/dcellar-web-ui/src/pages/api/bnb_price/index.tsx diff --git a/apps/dcellar-web-ui/src/facade/common.ts b/apps/dcellar-web-ui/src/facade/common.ts index 0bfca5b4..38b4194c 100644 --- a/apps/dcellar-web-ui/src/facade/common.ts +++ b/apps/dcellar-web-ui/src/facade/common.ts @@ -77,7 +77,7 @@ export const getObjectInfoAndBucketQuota = async ({ export const getBnbUsdtExchangeRate = async (): Promise => { const [res, error] = await get({ - url: 'https://bsc-explorer-api.nodereal.io/api/token/getPrice?symbol=bnb', + url: '/api/bnb_price', customOptions: { needNotify: false }, }).then(resolve, commonFault); diff --git a/apps/dcellar-web-ui/src/pages/api/bnb_price/index.tsx b/apps/dcellar-web-ui/src/pages/api/bnb_price/index.tsx new file mode 100644 index 00000000..552feb2d --- /dev/null +++ b/apps/dcellar-web-ui/src/pages/api/bnb_price/index.tsx @@ -0,0 +1,15 @@ +import axios from 'axios'; +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (req: NextApiRequest, res: NextApiResponse) => { + const url = `https://bsc-explorer-api.nodereal.io/api/token/getPrice?symbol=bnb`; + try { + const { data } = await axios.get(url); + res.json(data); + } catch (e) { + console.error('bnb_price', e); + res.json({}); + } +}; + +export default handler;