Giter Site home page Giter Site logo

victoriquemoe / typeorm-rate-limit-store Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 112 KB

A typeOrm store for the `express-rate-limit` middleware

Home Page: https://www.npmjs.com/package/typeorm-rate-limit-store

License: MIT License

JavaScript 26.92% TypeScript 71.96% Shell 1.12%

typeorm-rate-limit-store's Introduction

rate-limit-typeorm

A TypeORM store for express-rate-limit.
Designed for use with TypeORM as a backing store for express rate limiting in a clustered environment.

Installation

npm install typeorm-rate-limit-store

Usage

You will need to implement an entity for the rate-limiting model, and then instantiate the store by passing in that model.

Implement the IExpressRateLimitModel entity:

// ExpressRateLimitStoreModel.ts
import { Column, Entity, PrimaryColumn } from "typeorm";
import type {IExpressRateLimitModel} from 'typeorm-rate-limit-store';

@Entity()
export class ExpressRateLimitStoreModel implements IExpressRateLimitModel{
    @PrimaryColumn()
    public key: string;

    @Column()
    public totalHits: number;

    @Column()
    public resetTime: Date;
}

Instantiate the store passing in the model:

import {ExpressRateLimitTypeOrmStore} from 'typeorm-rate-limit-store';
import {ExpressRateLimitStoreModel} from "ExpressRateLimitStoreModel.js";

const repository = getDatastore().getRepository(ExpressRateLimitStoreModel)
app.use(
    rateLimit({
        windowMs: 1000,
        limit: 1,
        standardHeaders: true,
        store: new ExpressRateLimitTypeOrmStore(repository),
    }),
);

Options:

The ExpressRateLimitTypeOrmStore constructor takes the following parameters:

Option Description Required
repository The type orm repository that is built from the IExpressRateLimitModel interface True
prefix A string that will prefix the key, use this if you require multiple instances of the ExpressRateLimitTypeOrmStore False

Both CJS and ESM modules are provided, but it is assumed you will be using ESM as this package exports that as the default.

typeorm-rate-limit-store's People

Contributors

victoriquemoe avatar

Stargazers

Patrick Luzolo avatar Nathan Friedly avatar Vedant avatar Nick Maietta avatar Walker Boh avatar

Watchers

Patrick Luzolo avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.