Skip to content

Commit 79f7cb4

Browse files
authored
remove (#136)
1 parent 17f0203 commit 79f7cb4

1 file changed

Lines changed: 0 additions & 46 deletions

File tree

apps/company-website/api/contacts.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import fetch from 'node-fetch';
55
import { nanoid } from 'nanoid';
66
import { Client } from '@notionhq/client';
7-
import { Ratelimit } from '@upstash/ratelimit';
8-
// This path has to be specified because fetch is not natively supported
9-
// in node v17 and earlier
10-
import { Redis } from '@upstash/redis/with-fetch';
117

128
const notion = new Client({ auth: process.env.NOTION_TOKEN });
139

@@ -206,32 +202,6 @@ const processContact = async (event) => {
206202
}
207203
};
208204

209-
const allowRequest = async (request) => {
210-
try {
211-
const ip = request.ip ?? '127.0.0.1';
212-
213-
const ratelimit = new Ratelimit({
214-
limiter: Ratelimit.fixedWindow(1, '30 s'),
215-
/** Use fromEnv() to automatically load connection secrets from your environment
216-
* variables. For instance when using the Vercel integration.
217-
*
218-
* This tries to load `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from
219-
* your environment using `process.env`.
220-
*/
221-
redis: Redis.fromEnv(),
222-
});
223-
224-
const response = await ratelimit.limit(ip);
225-
return response;
226-
} catch (error) {
227-
throw {
228-
body: {
229-
message: error,
230-
},
231-
};
232-
}
233-
};
234-
235205
const contacts = async (req, res) => {
236206
try {
237207
if (!req.body) {
@@ -249,19 +219,6 @@ const contacts = async (req, res) => {
249219

250220
const { email, name, message } = req.body;
251221

252-
const {
253-
success, limit, reset, remaining,
254-
} = await allowRequest(req);
255-
256-
if (!success) {
257-
throw {
258-
statusCode: 429,
259-
body: {
260-
message: 'Too many requests. Please try again in a minute',
261-
},
262-
};
263-
}
264-
265222
try {
266223
await processContact({
267224
id: nanoid(),
@@ -277,9 +234,6 @@ const contacts = async (req, res) => {
277234
headers: {
278235
'Access-Control-Allow-Origin': '*',
279236
'Access-Control-Allow-Credentials': true,
280-
'X-RateLimit-Limit': limit.toString(),
281-
'X-RateLimit-Remaining': remaining.toString(),
282-
'X-RateLimit-Reset': reset.toString(),
283237
},
284238
});
285239
} catch (error) {

0 commit comments

Comments
 (0)