Skip to content

Commit

Permalink
feat: add httpMethodGuard middleware for api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
alx-khramov committed Jun 17, 2024
1 parent 5786131 commit 69ea21d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pages/api/eth-apr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
errorAndCacheDefaultWrappers,
responseTimeMetric,
rateLimit,
httpMethodGuard,
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';

Expand All @@ -31,6 +33,7 @@ const ethApr: API = async (_, res) => {
};

export default wrapNextRequest([
httpMethodGuard([HttpMethod.GET]),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.ETH_APR),
...errorAndCacheDefaultWrappers,
Expand Down
3 changes: 3 additions & 0 deletions pages/api/eth-price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
defaultErrorHandler,
responseTimeMetric,
rateLimit,
httpMethodGuard,
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';
import { API } from 'types';
Expand All @@ -36,6 +38,7 @@ const ethPrice: API = async (req, res) => {
};

export default wrapNextRequest([
httpMethodGuard([HttpMethod.GET]),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.ETH_PRICE),
cacheControl({ headers: config.CACHE_ETH_PRICE_HEADERS }),
Expand Down
3 changes: 3 additions & 0 deletions pages/api/ldo-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
errorAndCacheDefaultWrappers,
responseTimeMetric,
rateLimit,
httpMethodGuard,
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';
import { API } from 'types';
Expand Down Expand Up @@ -37,6 +39,7 @@ const ldoStats: API = async (req, res) => {
};

export default wrapNextRequest([
httpMethodGuard([HttpMethod.GET]),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.LDO_STATS),
...errorAndCacheDefaultWrappers,
Expand Down
3 changes: 3 additions & 0 deletions pages/api/lido-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
errorAndCacheDefaultWrappers,
responseTimeMetric,
rateLimit,
httpMethodGuard,
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';
import { API } from 'types';
Expand Down Expand Up @@ -35,6 +37,7 @@ const lidoStats: API = async (req, res) => {
};

export default wrapNextRequest([
httpMethodGuard([HttpMethod.GET]),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.LIDO_STATS),
...errorAndCacheDefaultWrappers,
Expand Down
3 changes: 3 additions & 0 deletions pages/api/lidostats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
responseTimeMetric,
errorAndCacheDefaultWrappers,
rateLimit,
httpMethodGuard,
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';
import { API } from 'types';
Expand Down Expand Up @@ -36,6 +38,7 @@ const lidoStats: API = async (req, res) => {
};

export default wrapNextRequest([
httpMethodGuard([HttpMethod.GET]),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.LIDOSTATS),
...errorAndCacheDefaultWrappers,
Expand Down
3 changes: 3 additions & 0 deletions pages/api/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
responseTimeMetric,
defaultErrorHandler,
requestAddressMetric,
httpMethodGuard,
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';
import { rpcUrls } from 'utilsApi/rpcUrls';
Expand Down Expand Up @@ -44,6 +46,7 @@ const rpc = rpcFactory({
});

export default wrapNextRequest([
httpMethodGuard([HttpMethod.POST]),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.RPC),
requestAddressMetric(Metrics.request.ethCallToAddress),
Expand Down
3 changes: 3 additions & 0 deletions pages/api/sma-steth-apr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
errorAndCacheDefaultWrappers,
rateLimit,
getSmaStethApr,
httpMethodGuard,
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';

Expand All @@ -33,6 +35,7 @@ const smaStethApr: API = async (_, res) => {
};

export default wrapNextRequest([
httpMethodGuard([HttpMethod.GET]),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.SMA_STETH_APR),
...errorAndCacheDefaultWrappers,
Expand Down
3 changes: 3 additions & 0 deletions pages/api/totalsupply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
defaultErrorHandler,
responseTimeMetric,
rateLimit,
httpMethodGuard,
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';
import { API } from 'types';
Expand All @@ -36,6 +38,7 @@ const totalSupply: API = async (req, res) => {
};

export default wrapNextRequest([
httpMethodGuard([HttpMethod.GET]),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.TOTALSUPPLY),
cacheControl({ headers: config.CACHE_TOTAL_SUPPLY_HEADERS }),
Expand Down

0 comments on commit 69ea21d

Please sign in to comment.