@@ -54,12 +54,13 @@ export class CustomThrottlerGuard extends ThrottlerGuard {
54
54
const { context } = requestProps ;
55
55
56
56
const request = context . switchToHttp ( ) . getRequest < Request > ( ) ;
57
+ const IP = request ?. headers ?. [ "cf-connecting-ip" ] ?? request ?. headers ?. [ "CF-Connecting-IP" ] ?? request . ip ;
57
58
const response = context . switchToHttp ( ) . getResponse < Response > ( ) ;
58
59
const tracker = await this . getTracker ( request ) ;
59
60
this . logger . verbose (
60
61
`Tracker "${ tracker } " generated based on: Bearer token "${ request . get (
61
62
"Authorization"
62
- ) } ", OAuth client ID "${ request . get ( X_CAL_CLIENT_ID ) } " and IP "${ request . ip } "`
63
+ ) } ", OAuth client ID "${ request . get ( X_CAL_CLIENT_ID ) } " and IP "${ IP } "`
63
64
) ;
64
65
65
66
if ( tracker . startsWith ( "api_key_" ) ) {
@@ -209,6 +210,7 @@ export class CustomThrottlerGuard extends ThrottlerGuard {
209
210
210
211
protected async getTracker ( request : Request ) : Promise < string > {
211
212
const authorizationHeader = request . get ( "Authorization" ) ?. replace ( "Bearer " , "" ) ;
213
+ const IP = request ?. headers ?. [ "cf-connecting-ip" ] ?? request ?. headers ?. [ "CF-Connecting-IP" ] ?? request . ip ;
212
214
213
215
if ( authorizationHeader ) {
214
216
const apiKeyPrefix = getEnv ( "API_KEY_PREFIX" , "cal_" ) ;
@@ -223,8 +225,8 @@ export class CustomThrottlerGuard extends ThrottlerGuard {
223
225
return `oauth_client_${ oauthClientId } ` ;
224
226
}
225
227
226
- if ( request . ip ) {
227
- return `ip_${ request . ip } ` ;
228
+ if ( IP ) {
229
+ return `ip_${ IP } ` ;
228
230
}
229
231
230
232
this . logger . verbose ( `no tracker found: ${ request . url } ` ) ;
0 commit comments