File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
cloudflare-worker/src/routes Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -192,14 +192,24 @@ export class Router {
192192 const { pathname } = url ;
193193
194194 // Apply rate limiting
195- const { success } = await env . RATE_LIMITER . limit ( { key : pathname } ) ;
195+ const ip = request . headers . get ( "CF-Connecting-IP" ) || "unknown" ;
196+ const userId = this . jwtPayload . sub || "anonymous" ;
197+ const endpoint = pathname ;
198+ const rateLimitKey = `${ ip } :${ userId } :${ endpoint } ` ;
199+ const { success } = await env . RATE_LIMITER . limit ( { key : rateLimitKey } ) ;
196200
197201 if ( ! success ) {
198202 return new Response (
199203 JSON . stringify ( `429 Failure – rate limit exceeded for ${ pathname } ` ) ,
200204 {
201205 status : 429 ,
202- headers : { ...this . corsHeaders } ,
206+ headers : {
207+ ...this . corsHeaders ,
208+ "X-RateLimit-Limit" : "10" ,
209+ "X-RateLimit-Remaining" : "0" ,
210+ "X-RateLimit-Reset" : "60" ,
211+ "Retry-After" : "60" ,
212+ } ,
203213 } ,
204214 ) ;
205215 }
You can’t perform that action at this time.
0 commit comments