@@ -14,17 +14,17 @@ export default defineEventHandler(async (event) => {
1414 return ;
1515 }
1616
17- console . log (
18- `👉 Handling request for URL: ${ event . node . req . url } from IP: ${
19- getRequestIP ( event , { xForwardedFor : true } ) || "unKnownIP"
20- } `
21- ) ;
17+ // console.log(
18+ // `👉 Handling request for URL: ${event.node.req.url} from IP: ${
19+ // getRequestIP(event, { xForwardedFor: true }) || "unKnownIP"
20+ // }`
21+ // );
2222
2323 const shieldStorage = useStorage ( "shield" ) ;
2424 const requestIP = getRequestIP ( event , { xForwardedFor : true } ) || "unKnownIP" ;
2525
2626 if ( ! ( await shieldStorage . hasItem ( `ip:${ requestIP } ` ) ) ) {
27- console . log ( "IP not found in storage, setting initial count." , requestIP ) ;
27+ // console.log("IP not found in storage, setting initial count.", requestIP);
2828 return await shieldStorage . setItem ( `ip:${ requestIP } ` , {
2929 count : 1 ,
3030 time : Date . now ( ) ,
@@ -33,12 +33,12 @@ export default defineEventHandler(async (event) => {
3333
3434 const req = ( await shieldStorage . getItem ( `ip:${ requestIP } ` ) ) as RateLimit ;
3535 req . count ++ ;
36- console . log ( `Set count for IP ${ requestIP } : ${ req . count } ` ) ;
36+ // console.log(`Set count for IP ${requestIP}: ${req.count}`);
3737
3838 shieldLog ( req , requestIP , event . node . req . url ) ;
3939
4040 if ( ! isRateLimited ( req ) ) {
41- console . log ( "Request not rate-limited, updating storage." ) ;
41+ // console.log("Request not rate-limited, updating storage.");
4242 return await shieldStorage . setItem ( `ip:${ requestIP } ` , {
4343 count : req . count ,
4444 time : req . time ,
@@ -85,12 +85,12 @@ export default defineEventHandler(async (event) => {
8585const isRateLimited = ( req : RateLimit ) => {
8686 const options = useRuntimeConfig ( ) . public . nuxtApiShield ;
8787
88- console . log ( `count: ${ req . count } > limit: ${ options . limit . max } ` ) ;
89- if ( req . count > options . limit . max ) {
90- return true ;
88+ // console.log(`count: ${req.count} <= limit: ${options.limit.max}`);
89+ if ( req . count <= options . limit . max ) {
90+ return false ;
9191 }
92- console . log ( ( Date . now ( ) - req . time ) / 1000 , "> " , options . limit . duration ) ;
93- return ( Date . now ( ) - req . time ) / 1000 > options . limit . duration ;
92+ // console.log((Date.now() - req.time) / 1000, "< ", options.limit.duration);
93+ return ( Date . now ( ) - req . time ) / 1000 < options . limit . duration ;
9494} ;
9595
9696const banDelay = async ( req : RateLimit ) => {
0 commit comments