11import { Client , isFullPage } from "@notionhq/client" ;
2- import { Ratelimit } from "@upstash/ratelimit" ;
3- import { Redis } from "@upstash/redis" ;
42import { nanoid } from "nanoid" ;
53import 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
3329const 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-
4031const createPayload = ( name : string , email : string , url : string ) => ( {
4132 channel : SLACK_CHANNEL ,
4233 blocks : [
@@ -266,29 +257,7 @@ const processContact = async (event: {
266257} ;
267258
268259const 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
294263export 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 ) ;
0 commit comments