How to add different rate limit condition for different user using express-gateway

616 Views Asked by At

I am trying to use the feature of rate limiting from express-gateway. But I am stuck on how to use different rate-limit value for different user.Also how to throttle only one end point. Here is my gateway.config.yml

http:
port: 9000
admin:
port: 9876
hostname: localhost
apiEndpoints:
cust:
host: localhost
paths:    
  - '/delete'
  - '/update'   
serviceEndpoints:
custsurv:
url: 'http://localhost:3000'
policies:

    basic-auth
    cors
    expression
    key-auth
    log
    oauth2
    proxy
    rate-limit
    pipelines:
    default:
    apiEndpoints:
        cust
        policies:
        rate-limit:
            action:
            max: 1
            windowMs: 100000
        proxy:
            action:
            serviceEndpoint: custsurv
            changeOrigin: true

Right now it is working for all user.

I have written one middleware from where I can authenticate user and it returns the userid from the token that client has sent.Here is my function from where I am getting different throttle value for different user

@Get('/delete')
  public async getsomelist(
    @CurrentUser({ required: true }) context: ContextValidator
  ): Promise<ActionResponseBody> {

    const throttlevalue=await  this.mysqlConn.executeQuery('databasequery',context.currentUser.userId);
  }

Please let me know if I need to provide some more information.

0

There are 0 best solutions below