From 776392bf9476248f1775d87f8ef601c66f015c1c Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Fri, 24 May 2024 11:11:27 +0100 Subject: [PATCH] Delete unnecesary files --- src/routes/proxies/coingecko/index.ts | 50 --------------------------- src/routes/proxies/tokens/index.ts | 18 ---------- 2 files changed, 68 deletions(-) delete mode 100644 src/routes/proxies/coingecko/index.ts delete mode 100644 src/routes/proxies/tokens/index.ts diff --git a/src/routes/proxies/coingecko/index.ts b/src/routes/proxies/coingecko/index.ts deleted file mode 100644 index 49d54cd..0000000 --- a/src/routes/proxies/coingecko/index.ts +++ /dev/null @@ -1,50 +0,0 @@ -import httpProxy from "@fastify/http-proxy"; -import { FastifyPluginAsync } from "fastify"; - -const CACHE_TTL = 1 * 60; // 1 min in s -const SERVER_CACHE_TTL = 1.5 * 60; // 1.5 min in s -const DEFAULT_COINGECKO_PROXY_UPSTREAM = "https://api.coingecko.com"; - -const coingeckoProxy: FastifyPluginAsync = async ( - fastify, - opts -): Promise => { - fastify.register(httpProxy, { - upstream: - fastify.config.COINGECKO_PROXY_UPSTREAM || - DEFAULT_COINGECKO_PROXY_UPSTREAM, - rewritePrefix: "/api/v3/", - replyOptions: { - rewriteRequestHeaders: (request, headers) => ({ - ...headers, - "x-cg-pro-api-key": fastify.config.COINGECKO_API_KEY, - }), - // Response headers https://github.com/fastify/fastify-reply-from?tab=readme-ov-file#rewriteheadersheaders-request - rewriteHeaders: (originalHeaders, request) => { - const { - // Drop set-cookie header to allow Vercel CDN caching https://vercel.com/docs/edge-network/caching#cacheable-response-criteria - "set-cookie": _, - "cache-control": cacheControl, - ...headers - } = originalHeaders; - - return { - ...headers, - // Only replace `cache-control` if it was set in the response - ...(cacheControl - ? { - "cache-control": `max-age=${CACHE_TTL}, public, s-maxage=${SERVER_CACHE_TTL}`, - // Add `cdn-cache-control` otherwise Vercel strips `s-maxage` from `cache-control` - "cdn-cache-control": `max-age=${SERVER_CACHE_TTL}`, - } - : undefined), - }; - }, - }, - undici: { - strictContentLength: false, // Prevent errors when content-length header mismatches - }, - }); -}; - -export default coingeckoProxy; diff --git a/src/routes/proxies/tokens/index.ts b/src/routes/proxies/tokens/index.ts deleted file mode 100644 index 5ea9e0d..0000000 --- a/src/routes/proxies/tokens/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { FastifyPluginAsync } from "fastify"; -import httpProxy from "@fastify/http-proxy"; - -const proxy: FastifyPluginAsync = async (fastify, opts): Promise => { - fastify.register(httpProxy, { - upstream: fastify.config.PROXY_UPSTREAM, - replyOptions: { - rewriteRequestHeaders: (originalRequest: any, headers: any) => { - return { - ...headers, - Origin: fastify.config.PROXY_ORIGIN, - }; - }, - }, - }); -}; - -export default proxy;