Skip to content

Commit

Permalink
Merge pull request #24 from dreampipcom/dev
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
angeloreale committed Aug 7, 2024
2 parents ad259b1 + 7da7245 commit 80b8d9a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint @typescript-eslint/no-unused-vars:0 */
// middleware.ts
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
import { next } from '@vercel/edge';
import { ipAddress } from '@vercel/functions';
import { kv } from '@vercel/kv';
import { NextResponse } from 'next/server';
import { Ratelimit } from '@upstash/ratelimit';
// import { kv } from '@vercel/kv';
// import { Ratelimit } from '@upstash/ratelimit';

const ratelimit = new Ratelimit({
redis: kv,
limiter: Ratelimit.slidingWindow(10, '3 s'),
});
// const ratelimit = new Ratelimit({
// redis: kv,
// limiter: Ratelimit.slidingWindow(10, '3 s'),
// });

export const config = {
matcher: ['/api/:path*'],
Expand All @@ -31,14 +31,14 @@ export default async function middleware(request: NextRequest) {
const response = next();
const ip = ipAddress(request) || '127.0.0.1';

const { success, pending, limit, reset, remaining } = await ratelimit.limit(ip);
// const { success, pending, limit, reset, remaining } = await ratelimit.limit(ip);

if (!request?.url?.includes('auth')) {
Object.keys(headers).forEach((key: string) => {
response.headers.set(key, headers[key]);
});
}

return success ? response : NextResponse.redirect(new URL('https://www.dreampip.com/404', request.url));
// return response ? response : NextResponse.redirect(new URL('https://www.dreampip.com/404', request.url));
// return success ? response : NextResponse.redirect(new URL('https://www.dreampip.com/404', request.url));
return response ? response : NextResponse.redirect(new URL('https://www.dreampip.com/404', request.url));
}

0 comments on commit 80b8d9a

Please sign in to comment.