diff --git a/pages/api/oneinch-rate.ts b/pages/api/oneinch-rate.ts index 80132650b..473d8f58b 100644 --- a/pages/api/oneinch-rate.ts +++ b/pages/api/oneinch-rate.ts @@ -1,4 +1,7 @@ -import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; +import { + cacheControl, + wrapRequest as wrapNextRequest, +} from '@lidofinance/next-api-wrapper'; import { config } from 'config'; import { @@ -24,6 +27,7 @@ export default wrapNextRequest([ cors({ origin: ['*'], methods: [HttpMethod.GET] }), rateLimit, responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.ONEINCH_RATE), + cacheControl({ headers: config.CACHE_DEFAULT_HEADERS }), sunsetBy({ sunsetTimestamp: API_LATER_SUNSET_TIMESTAMP, replacementLink: getReplacementLink(API_ROUTES.ONEINCH_RATE), diff --git a/pages/api/short-lido-stats.ts b/pages/api/short-lido-stats.ts index b8b694e1c..64e30dd2a 100644 --- a/pages/api/short-lido-stats.ts +++ b/pages/api/short-lido-stats.ts @@ -1,4 +1,7 @@ -import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; +import { + cacheControl, + wrapRequest as wrapNextRequest, +} from '@lidofinance/next-api-wrapper'; import { config } from 'config'; import { @@ -25,6 +28,7 @@ export default wrapNextRequest([ cors({ origin: ['*'], methods: [HttpMethod.GET] }), rateLimit, responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.SHORT_LIDO_STATS), + cacheControl({ headers: config.CACHE_DEFAULT_HEADERS }), sunsetBy({ sunsetTimestamp: API_LATER_SUNSET_TIMESTAMP, replacementLink: getReplacementLink(API_ROUTES.SHORT_LIDO_STATS), diff --git a/pages/api/sma-steth-apr.ts b/pages/api/sma-steth-apr.ts index 4d21ea1cf..5cbdbbada 100644 --- a/pages/api/sma-steth-apr.ts +++ b/pages/api/sma-steth-apr.ts @@ -1,4 +1,7 @@ -import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; +import { + cacheControl, + wrapRequest as wrapNextRequest, +} from '@lidofinance/next-api-wrapper'; import { config } from 'config'; import { @@ -24,6 +27,7 @@ export default wrapNextRequest([ cors({ origin: ['*'], methods: [HttpMethod.GET] }), rateLimit, responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.SMA_STETH_APR), + cacheControl({ headers: config.CACHE_DEFAULT_HEADERS }), sunsetBy({ sunsetTimestamp: API_DEFAULT_SUNSET_TIMESTAMP, replacementLink: getReplacementLink(API_ROUTES.SMA_STETH_APR), diff --git a/utilsApi/cached-proxy.ts b/utilsApi/cached-proxy.ts index 3fb334a7d..5710baa8c 100644 --- a/utilsApi/cached-proxy.ts +++ b/utilsApi/cached-proxy.ts @@ -40,7 +40,10 @@ export const createCachedProxy = ({ const cacheKey = `${proxyUrl}-${params?.toString() ?? ''}`; const cachedValue = cache.get(cacheKey); - if (cachedValue) return cachedValue; + if (cachedValue) { + res.json(cachedValue); + return; + } const url = proxyUrl + (params ? `?${params.toString()}` : ''); @@ -65,6 +68,8 @@ export const createCachedProxy = ({ if (e instanceof FetcherError && e.status >= 400 && e.status < 500) { console.warn(`[CachedProxy]Forwarding ${e.status} error from ${url}`); res.status(e.status); + res.json({ error: e.message }); + return; } console.warn(`[CachedProxy] Failed to proxy from ${url}`, e); res.status(500).end();