req-dedup-middleware
This middleware aims to avoid duplicated requests made by the client.
Installation
yarn add req-dedup-middleware
# Storage
yarn add @keyv/redis
# or
yarn add @keyv/mongo
Usage :
import duplicate from "req-dedup-middleware";
const duplicate = require("req-dedup-middleware").default;
const express = require("express");
const app = express();
app.use(duplicate({
expiration: 10000,
key: "requestId",
prefix: "root"
}));
app.get("/", (req, res) => res.end("Hey!"));
app.listen(8080, () => console.log("Listening!"));
Options
{
expiration: 10000,
key: "id",
prefix: "requests",
response: {
statusCode: 429,
json: {}
},
connectionUri: ""
}
External storage
If you want to use an external storage (currently supported are Redis and MongoDB), you need to install one of the following package :
yarn add @keyv/mongo
yarn add @keyv/redis