diff --git a/packages/api/env.mjs b/packages/api/env.mjs index aa2cf4d5..aa85c631 100644 --- a/packages/api/env.mjs +++ b/packages/api/env.mjs @@ -9,6 +9,7 @@ export const env = createEnv({ UPSTASH_REDIS_REST_TOKEN: z.string().min(1), UPSTASH_RATELIMITER_TOKENS_PER_TIME: z.string().min(1), UPSTASH_RATELIMITER_TIME_INTERVAL: z.string().min(1), + UPSTASH_RATELIMITER_EXCLUDED_IPS: z.string().min(1), RESEND_API_KEY: z.string().min(1), QWEATHER_API_KEY: z.string().min(1), API_NINJA_API_KEY: z.string().min(1) diff --git a/packages/api/src/routers/weather.ts b/packages/api/src/routers/weather.ts index 64da4b8a..2b8a40be 100644 --- a/packages/api/src/routers/weather.ts +++ b/packages/api/src/routers/weather.ts @@ -1,4 +1,5 @@ -import axios, { AxiosResponse } from "axios"; +import type { AxiosResponse } from "axios"; +import axios from "axios"; import dayjs from "dayjs"; import timezone from "dayjs/plugin/timezone"; import utc from "dayjs/plugin/utc"; diff --git a/packages/api/src/trpc.ts b/packages/api/src/trpc.ts index cbaa42f3..845304b4 100644 --- a/packages/api/src/trpc.ts +++ b/packages/api/src/trpc.ts @@ -125,8 +125,15 @@ const ratelimit = new Ratelimit({ prefix: "@upstash/ratelimit", }); +const EXCLUDED_IPS = env.UPSTASH_RATELIMITER_EXCLUDED_IPS.split(","); + const rateLimitMiddleware = t.middleware(async ({ ctx, path, next }) => { const identifier = `${ctx.ip}:${path}`; + + if (EXCLUDED_IPS.includes(ctx.ip)) { + return next(); + } + // log.debug("identifier", { identifier }); const { success, remaining } = await ratelimit.limit(identifier); // log.debug("remaining", { remaining }); diff --git a/turbo.json b/turbo.json index ba0c7f23..6af0fd18 100644 --- a/turbo.json +++ b/turbo.json @@ -53,6 +53,7 @@ "UPSTASH_REDIS_REST_TOKEN", "UPSTASH_RATELIMITER_TOKENS_PER_TIME", "UPSTASH_RATELIMITER_TIME_INTERVAL", + "UPSTASH_RATELIMITER_EXCLUDED_IPS", "RESEND_API_KEY", "QWEATHER_API_KEY", "API_NINJA_API_KEY",