From 9a15fe7fd2a69611c22ba8e0152f503b3e53aaa2 Mon Sep 17 00:00:00 2001 From: davidabram Date: Tue, 22 Jul 2025 13:28:55 +0200 Subject: [PATCH] remove redis --- apps/contact/app/api/contact/route.ts | 49 ++++----------------------- apps/contact/package.json | 2 -- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/apps/contact/app/api/contact/route.ts b/apps/contact/app/api/contact/route.ts index 0a796290..8f2e1534 100644 --- a/apps/contact/app/api/contact/route.ts +++ b/apps/contact/app/api/contact/route.ts @@ -1,6 +1,4 @@ import { Client, isFullPage } from "@notionhq/client"; -import { Ratelimit } from "@upstash/ratelimit"; -import { Redis } from "@upstash/redis"; import { nanoid } from "nanoid"; import z from "zod"; @@ -25,18 +23,11 @@ const { MENTION_EMAILS, MENTION_IDS, NOTION_DATABASE_ID, - UPSTASH_REDIS_REST_URL, - UPSTASH_REDIS_REST_TOKEN, IS_OFFLINE, } = process.env; const notion = new Client({ auth: NOTION_TOKEN }); -const redis = new Redis({ - url: UPSTASH_REDIS_REST_URL, - token: UPSTASH_REDIS_REST_TOKEN, -}); - const createPayload = (name: string, email: string, url: string) => ({ channel: SLACK_CHANNEL, blocks: [ @@ -266,29 +257,7 @@ const processContact = async (event: { }; const allowRequest = async (request: Request & { ip?: string }) => { - try { - const ip = request.ip ?? "127.0.0.1"; - - const ratelimit = new Ratelimit({ - limiter: Ratelimit.fixedWindow(1, "30 s"), - /** Use fromEnv() to automatically load connection secrets from your environment - * variables. For instance when using the Vercel integration. - * - * This tries to load `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from - * your environment using `import.meta.env`. - */ - redis, - }); - - const response = await ratelimit.limit(ip); - return response; - } catch (error) { - throw { - body: { - message: error, - }, - }; - } + return { success: true, limit: 1, reset: Date.now() + 30000, remaining: 1 }; }; export async function OPTIONS() { @@ -318,8 +287,7 @@ export async function POST(request: Request) { if (!body || bodyValidationResult.error) { return new Response( JSON.stringify({ - message: - bodyValidationResult.error?.message || "No body was found", + message: bodyValidationResult.error?.message || "No body was found", }), { status: 400, @@ -333,15 +301,12 @@ export async function POST(request: Request) { const { name, email, message, hasConsent } = body; if (!hasConsent) { - return new Response( - JSON.stringify({ message: "No consent by user" }), - { - status: 403, - headers: { - ...corsHeaders, - }, + return new Response(JSON.stringify({ message: "No consent by user" }), { + status: 403, + headers: { + ...corsHeaders, }, - ); + }); } const { success, limit, reset, remaining } = await allowRequest(request); diff --git a/apps/contact/package.json b/apps/contact/package.json index dd798421..0322079b 100644 --- a/apps/contact/package.json +++ b/apps/contact/package.json @@ -13,8 +13,6 @@ "react-dom": "^19.0.0", "next": "15.2.3", "@notionhq/client": "^2.2.15", - "@upstash/ratelimit": "^2.0.5", - "@upstash/redis": "^1.34.3", "nanoid": "^5.0.9", "zod": "^3.24.1" },