From c9eda78219ef842802cd213566ae187d90a2bcf4 Mon Sep 17 00:00:00 2001 From: Tomek Marciniak Date: Tue, 3 Sep 2024 09:14:33 +0200 Subject: [PATCH] chore(klesia): adjust rate limiter --- apps/klesia/src/index.ts | 6 +++++- packages/klesia-sdk/src/client.ts | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/klesia/src/index.ts b/apps/klesia/src/index.ts index 334e5c3..67617c7 100644 --- a/apps/klesia/src/index.ts +++ b/apps/klesia/src/index.ts @@ -19,7 +19,11 @@ const api = new OpenAPIHono(); api.use(logger()); api.use( rateLimiter({ - keyGenerator: (c) => getConnInfo(c).remote.address ?? nanoid(), + skip: (c) => c.req.path !== "/api" || c.req.method !== "POST", + keyGenerator: (c) => + c.req.header("x-forwarded-for") ?? + getConnInfo(c).remote.address ?? + nanoid(), limit: 10, }), ); diff --git a/packages/klesia-sdk/src/client.ts b/packages/klesia-sdk/src/client.ts index 2208505..8bf3604 100644 --- a/packages/klesia-sdk/src/client.ts +++ b/packages/klesia-sdk/src/client.ts @@ -5,7 +5,9 @@ import { z } from "zod"; const NetworkMatcher = z.enum(["mainnet", "devnet"]); -export const createClient = ({ network }: { network: 'mainnet' | 'devnet' }) => { +export const createClient = ({ + network, +}: { network: "mainnet" | "devnet" }) => { return match(NetworkMatcher.parse(network)) .with("devnet", () => hc("https://devnet.klesia.palladians.xyz/api"), @@ -13,5 +15,5 @@ export const createClient = ({ network }: { network: 'mainnet' | 'devnet' }) => .with("mainnet", () => hc("https://mainnet.klesia.palladians.xyz/api"), ) - .exhaustive(); + .exhaustive(); };