moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
291 stars 119 forks source link

rateLimit in routes level #271

Closed filiafobico closed 2 years ago

filiafobico commented 2 years ago

What it does

A simple suggestion to configure rateLimit in route level.

Example

const ApiGateway = require('moleculer-web')

module.exports = {
  name: 'api',
  mixins: [ApiGateway],
  settings: {
    rateLimit: rateLimitGlobalConfig,
    routes: [
      {
        path: '/withLocalRateLimit',
        // now you can pass rateLimit here
        // it will override the global rateLimit
        rateLimit: rateLimitConfig,
        aliases: {
          'GET /2': 'test.2'
        }
      },
      {
        path: '/withGlobalRateLimit',
        aliases: {
          'GET /1': 'test.1'
        }
      }
    ]
  }
}

Obs

If you like the suggestion, I can create relevant tests

issues

resolve #18

filiafobico commented 2 years ago

@icebob could you create a new "next" version with these changes? I would like to use them at work

icebob commented 2 years ago

I don't release betas only before major versions. You can install the current version with npm i moleculerjs/moleculer-web

icebob commented 2 years ago

It's just been released.