Skip to content

Implement Expressjs Rate Limit Middleware #113

Closed

Description

@rsaz

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

We have a middleware service where we do add services that can be used dynamically by the developer during the application development like so:

@provide(App)
export class App extends AppExpress {
    private middleware: IMiddleware;
    private provider: IProvider;

    constructor() {
        super();
        this.middleware = container.get<IMiddleware>(Middleware);
        this.provider = container.get<IProvider>(Provider);
    }

    protected configureServices(): void {
        this.middleware.addBodyParser();
        this.middleware.setErrorHandler();
    }

    protected postServerInitialization(): void {
        if (this.isDevelopment()) {
            this.provider.envValidator.checkAll();
        }
    }

    protected serverShutdown(): void {}
}

The middleware are added in the middleware service as mentioned above as well as it's interfaces implemented here.
The interfaces are the options that can be optionally passed to the middleware.

This task has the objective of implementing the middleware express-rate-limit embedded in the ExpressoTS platform as the other middlewares.

More information here: https://github.com/express-rate-limit/express-rate-limit

Steps to reproduce

N/A

Expected behavior

Implemented express-rate-limit middleware and make it available as an option in the application provider class

Package version

2.2.1

Node.js version

18

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Activity

  1. added
    enhancement
    good first issue
    needs triage
    hacktoberfest
    on Sep 30, 2023
  2. devsargam commented on Sep 30, 2023

    @devsargam
    Contributor

    @rsaz may I start working on this?? Can you please assign this to me?

  3. rsaz commented on Sep 30, 2023

    @rsaz
    MemberAuthor

    @rsaz may I start working on this?? Can you please assign this to me?

    Assigned to you. Good work! Looking forward to review your PR!

  4. moved this to 💻 In Development in Expressots Projecton Sep 30, 2023
  5. devsargam commented on Oct 1, 2023

    @devsargam
    Contributor

    @rsaz I have implemented the required interface and added it in middleware-service.ts.
    But can you pin point how can I test it?

  6. rsaz commented on Oct 1, 2023

    @rsaz
    MemberAuthor

    @rsaz I have implemented the required interface and added it in middleware-service.ts. But can you pin point how can I test it?

    In order for you test you have to build your library. Here are all the steps prior to the build:

    1 - install the cli globally

    npm i @expressots/cli

    2 - scaffold a project using the cli

    expressots new app-test -t opinionated -p npm

    3 - in the project dependencies of the app-test remove @expressots/core

    npm uninstall @expressots/core

    4 - rename your .env.example in to .env only

    5 -Now let's build the library with your changes

    npm run build

    If everything goes right it will generate a /lib folder container all lib code including your changes

    6 - Let's generate the package to test locally. npm pack will generate .tgz package in which you can install in your app-test to replace the @expressots/core package you removed in the step 3

    npm pack

    7 - it will be something like: npm i expressots-core-2.3.0.tgz

    After done that just run npm run dev in your app-test application.
    Go in providers/application folder in the application.provider.ts mentioned in the issue content right in the top.
    And in the section of configuring services you should be able to invoke your middleware for example:

    protected configureServices(): void {
            this.middleware.addRateLimit({}); // and pass your parameters, which represents the interface you have created
             this.middleware.addBodyParser();
            
            this.middleware.setErrorHandler();
        }

    The first test should be:
    1 - if you dont have the rate limit package installed by the time you execute the application using npm run dev you should throw a warning in the console saying, you should install the package for the rate limit middleware. Once you install, this warning should go away then you could use your middleware normally.

    2 - to really test your middleware working you should invoke any endpoint already created in the opinionated template. there is a folder user inside of useCases, and inside of this folder you will see several use cases such as create, delete, update and so on.
    The controllers of each usecase are the entry points of each request.

    Now is with you, any other doubt you might have you can query the documentatin, but with this information you already have 90% in your hand.

    Happy coding and good studies.

  7. moved this from 💻 In Development to ✅ Done in Expressots Projecton Oct 1, 2023
  8. rsaz commented on Oct 1, 2023

    @rsaz
    MemberAuthor

    Closed in the PR #115
    Author: @devsargam

  9. added a commit that references this issue on Aug 17, 2026
    fb9bc06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgood first issuehacktoberfestneeds triage

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions