mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-05-01 11:19:34 +00:00
Added Arcjet Security and Updated Caching on Cards
This commit is contained in:
parent
06aac8524a
commit
611adcddff
9 changed files with 261 additions and 19 deletions
|
@ -37,8 +37,8 @@ export async function GET(
|
|||
status: 200,
|
||||
headers: {
|
||||
'Cache-Control': 'public, s-maxage=1',
|
||||
'CDN-Cache-Control': 'public, s-maxage=60',
|
||||
'Vercel-CDN-Cache-Control': 'public, s-maxage=120',
|
||||
'CDN-Cache-Control': 'public, s-maxage=30',
|
||||
'Vercel-CDN-Cache-Control': 'public, s-maxage=60',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
|
|
|
@ -42,8 +42,8 @@ export async function GET(
|
|||
status: 200,
|
||||
headers: {
|
||||
'Cache-Control': 'public, s-maxage=1',
|
||||
'CDN-Cache-Control': 'public, s-maxage=60',
|
||||
'Vercel-CDN-Cache-Control': 'public, s-maxage=120',
|
||||
'CDN-Cache-Control': 'public, s-maxage=30',
|
||||
'Vercel-CDN-Cache-Control': 'public, s-maxage=60',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
|
|
|
@ -1,8 +1,31 @@
|
|||
import arcjet, { fixedWindow } from '@/lib/arcjet';
|
||||
import { unsplash } from '@/lib/unsplash';
|
||||
|
||||
import { auth } from '@clerk/nextjs/server';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET() {
|
||||
const aj = arcjet.withRule(
|
||||
fixedWindow({
|
||||
mode: 'LIVE',
|
||||
max: 10,
|
||||
window: '60s',
|
||||
})
|
||||
);
|
||||
|
||||
export async function GET(req: Request) {
|
||||
try {
|
||||
const { orgId, userId } = await auth();
|
||||
if (!orgId || !userId)
|
||||
return new NextResponse(JSON.stringify({ error: 'Unauthorized' }), {
|
||||
status: 401,
|
||||
});
|
||||
|
||||
const decision = await aj.protect(req);
|
||||
if (decision.isDenied())
|
||||
return new NextResponse(
|
||||
JSON.stringify({ error: 'Too many requests', reason: decision.reason }),
|
||||
{ status: 429 }
|
||||
);
|
||||
const result = await unsplash.photos.getRandom({
|
||||
collectionIds: ['317099'],
|
||||
count: 9,
|
||||
|
|
|
@ -4,8 +4,24 @@ import { NextResponse } from 'next/server';
|
|||
|
||||
import { db } from '@/lib/db';
|
||||
import { stripe } from '@/lib/stripe';
|
||||
import arcjet, { fixedWindow } from '@/lib/arcjet';
|
||||
|
||||
const aj = arcjet.withRule(
|
||||
fixedWindow({
|
||||
mode: 'LIVE',
|
||||
max: 10,
|
||||
window: '60s',
|
||||
})
|
||||
);
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const decision = await aj.protect(req);
|
||||
if (decision.isDenied())
|
||||
return new NextResponse(
|
||||
JSON.stringify({ error: 'Too many requests', reason: decision.reason }),
|
||||
{ status: 429 }
|
||||
);
|
||||
|
||||
const body = await req.text();
|
||||
const signature = (await headers()).get('Stripe-Signature') as string;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue