1
1
import { NextRequest , NextResponse } from "next/server" ;
2
2
import { detectBot , slidingWindow } from "@arcjet/next" ;
3
3
import { currentUser } from "@clerk/nextjs/server" ;
4
- import { aj } from "@/lib/arcjet" ;
4
+ import { arcjet } from "@/lib/arcjet" ;
5
5
import { permit } from "@/lib/permit" ;
6
6
import { getLastFriday } from "@/lib/dateHelper" ;
7
7
import { getOrderCount , getToppings } from "@/data/stats" ;
@@ -13,8 +13,8 @@ async function getClient() {
13
13
const user = await currentUser ( ) ;
14
14
if ( ! user ) {
15
15
return (
16
- aj
17
- // Add a sliding window rule to limit the number of requests to 5 per minute
16
+ arcjet
17
+ // Add a sliding window to limit requests to 5 per minute
18
18
. withRule ( slidingWindow ( { mode : "LIVE" , max : 5 , interval : 60 } ) )
19
19
// Add bot detection to block automated requests
20
20
. withRule ( detectBot ( { mode : "LIVE" , block : [ "AUTOMATED" ] } ) )
@@ -25,18 +25,21 @@ async function getClient() {
25
25
// then give them a medium rate limit.
26
26
const canUpdate = await permit . check ( user . id , "update" , "stats" ) ;
27
27
if ( ! canUpdate ) {
28
- return aj . withRule (
29
- // Add a sliding window rule to limit the number of requests to 10 per minute
30
- slidingWindow ( { mode : "LIVE" , max : 10 , interval : 60 } )
28
+ return (
29
+ arcjet
30
+ // Add a sliding window to limit requests to 10 per minute
31
+ . withRule ( slidingWindow ( { mode : "LIVE" , max : 10 , interval : 60 } ) )
31
32
) ;
32
33
}
33
34
34
- // User is logged in and has permission to update stats, so give them no rate limit
35
- return aj ;
35
+ // User is logged in and has permission to update stats,
36
+ // so give them no rate limit
37
+ return arcjet ;
36
38
}
37
39
38
40
export async function GET ( req : NextRequest ) {
39
- // Get the user's ID if they are logged in, otherwise use their IP address as a fingerprint
41
+ // Get the user's ID if they are logged in, otherwise use
42
+ // their IP address as a fingerprint
40
43
const user = await currentUser ( ) ;
41
44
const fingerprint : string = user ? user . id : req . ip ! ;
42
45
0 commit comments