Skip to content

Commit

Permalink
hotfix(selector+api): legacy stats
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewklau committed Oct 10, 2024
1 parent d50e9c0 commit 12a3338
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
13 changes: 1 addition & 12 deletions apps/api/src/middlewares/rateLimiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ const FREE_PLAN: Plan = {
title: 'Free Plan',
};
const KITWALLET_PATH = '/v1/kitwallet';
const LEGACY_PATH = '/v1/legacy';

const SUBNETS = [
'10.0.0.0/8',
'172.16.0.0/12',
'192.168.0.0/16',
'193.70.74.48/32',
];
const SUBNETS = ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'];

const rateLimiter = catchAsync(
async (req: Request, res: Response, next: NextFunction) => {
Expand All @@ -62,11 +56,6 @@ const rateLimiter = catchAsync(
const authHeader = req.headers.authorization || '';
const token = authHeader.replace('Bearer ', '');

if (req.baseUrl === LEGACY_PATH) {
logger.info('LEGACY_PATH');
return next();
}

if (config.apiAccessKey && token === config.apiAccessKey) {
return next();
}
Expand Down
4 changes: 3 additions & 1 deletion apps/explorer-selector/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const network = env('NEXT_PUBLIC_NETWORK_ID');
const mainnetApiUrl =
env('NEXT_PUBLIC_MAINNET_API_URL') || 'https://api.nearblocks.io/v1';
const testnetApiUrl =
env('NEXT_PUBLIC_TESTNET_API_URL') || 'https://api.nearblocks.io/v1';
env('NEXT_PUBLIC_TESTNET_API_URL') || 'https://api-testnet.nearblocks.io/v1';
configureRuntimeEnv();

/** @type {import('next').NextConfig} */
Expand All @@ -32,13 +32,15 @@ const nextConfig = {
? `${mainnetApiUrl}/node/telemetry`
: `${testnetApiUrl}/node/telemetry`,
},
/*
{
source: '/api/circulating-supply',
destination:
network === 'mainnet'
? `${mainnetApiUrl}/legacy/circulating-supply`
: `${testnetApiUrl}/legacy/circulating-supply`,
},
*/
{
source: '/api/circulating-supply-in-near',
destination:
Expand Down
35 changes: 35 additions & 0 deletions apps/explorer-selector/src/pages/api/circulating-supply.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(
_req: NextApiRequest,
res: NextApiResponse
) {
const apiKey = process.env.API_ACCESS_KEY;
const network = process.env.NEXT_PUBLIC_NETWORK_ID;
const mainnetApiUrl = 'https://api.nearblocks.io/v1';
const testnetApiUrl = 'https://api-testnet.nearblocks.io/v1';

const url =
network === 'mainnet'
? `${mainnetApiUrl}/legacy/circulating-supply`
: `${testnetApiUrl}/legacy/circulating-supply`;

try {
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Failed to fetch data');
}

const data = await response.json();
res.status(200).json(data);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch circulating supply data' });
}
}

0 comments on commit 12a3338

Please sign in to comment.