Skip to content

Commit 53cdca0

Browse files
authored
remove redis (#531)
1 parent daa39f0 commit 53cdca0

File tree

2 files changed

+7
-44
lines changed

2 files changed

+7
-44
lines changed

apps/contact/app/api/contact/route.ts

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Client, isFullPage } from "@notionhq/client";
2-
import { Ratelimit } from "@upstash/ratelimit";
3-
import { Redis } from "@upstash/redis";
42
import { nanoid } from "nanoid";
53
import z from "zod";
64

@@ -25,18 +23,11 @@ const {
2523
MENTION_EMAILS,
2624
MENTION_IDS,
2725
NOTION_DATABASE_ID,
28-
UPSTASH_REDIS_REST_URL,
29-
UPSTASH_REDIS_REST_TOKEN,
3026
IS_OFFLINE,
3127
} = process.env;
3228

3329
const notion = new Client({ auth: NOTION_TOKEN });
3430

35-
const redis = new Redis({
36-
url: UPSTASH_REDIS_REST_URL,
37-
token: UPSTASH_REDIS_REST_TOKEN,
38-
});
39-
4031
const createPayload = (name: string, email: string, url: string) => ({
4132
channel: SLACK_CHANNEL,
4233
blocks: [
@@ -266,29 +257,7 @@ const processContact = async (event: {
266257
};
267258

268259
const allowRequest = async (request: Request & { ip?: string }) => {
269-
try {
270-
const ip = request.ip ?? "127.0.0.1";
271-
272-
const ratelimit = new Ratelimit({
273-
limiter: Ratelimit.fixedWindow(1, "30 s"),
274-
/** Use fromEnv() to automatically load connection secrets from your environment
275-
* variables. For instance when using the Vercel integration.
276-
*
277-
* This tries to load `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from
278-
* your environment using `import.meta.env`.
279-
*/
280-
redis,
281-
});
282-
283-
const response = await ratelimit.limit(ip);
284-
return response;
285-
} catch (error) {
286-
throw {
287-
body: {
288-
message: error,
289-
},
290-
};
291-
}
260+
return { success: true, limit: 1, reset: Date.now() + 30000, remaining: 1 };
292261
};
293262

294263
export async function OPTIONS() {
@@ -318,8 +287,7 @@ export async function POST(request: Request) {
318287
if (!body || bodyValidationResult.error) {
319288
return new Response(
320289
JSON.stringify({
321-
message:
322-
bodyValidationResult.error?.message || "No body was found",
290+
message: bodyValidationResult.error?.message || "No body was found",
323291
}),
324292
{
325293
status: 400,
@@ -333,15 +301,12 @@ export async function POST(request: Request) {
333301
const { name, email, message, hasConsent } = body;
334302

335303
if (!hasConsent) {
336-
return new Response(
337-
JSON.stringify({ message: "No consent by user" }),
338-
{
339-
status: 403,
340-
headers: {
341-
...corsHeaders,
342-
},
304+
return new Response(JSON.stringify({ message: "No consent by user" }), {
305+
status: 403,
306+
headers: {
307+
...corsHeaders,
343308
},
344-
);
309+
});
345310
}
346311

347312
const { success, limit, reset, remaining } = await allowRequest(request);

apps/contact/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
"react-dom": "^19.0.0",
1414
"next": "15.2.3",
1515
"@notionhq/client": "^2.2.15",
16-
"@upstash/ratelimit": "^2.0.5",
17-
"@upstash/redis": "^1.34.3",
1816
"nanoid": "^5.0.9",
1917
"zod": "^3.24.1"
2018
},

0 commit comments

Comments
 (0)