host-locker

1.0.1 • Public • Published

host-locker

HostLocker is a Node.js middleware class designed for rate-limiting and controlling access based on the number of requests within a specified time window from specific origins.

Table of Contents

About

The library checks if a given origin is allowed to make a request based on the configured rate-limiting parameters.

Installation and usage

  • Install the host-locker module using npm:
$ npm install host-locker
  • Usage
const HostLocker = require('host-locker');

// Initialize HostLocker with configuration
const hostLimiter = new HostLocker({
  maxCallThreshold: 5, // Maximum allowed calls within the specified time window (default: 5)
  secondsThreshold: 5, // Time window in seconds (default: 5)
  allowedOrigins: ['example.com', 'api.example.com']  // Allowed hosts (default: [])
});

// Check if a host is allowed to make a request
const isAllowed = hostLimiter.check('example.com');

if (isAllowed) {
  // Proceed with the request
  console.log('Request allowed!');
} else {
  // Deny the request
  console.log('Access denied. Too many requests from this host.');
}

Support

This library used jsdoc types and is tested in Chrome

/host-locker/

    Package Sidebar

    Install

    npm i host-locker

    Weekly Downloads

    0

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    5.11 kB

    Total Files

    3

    Last publish

    Collaborators

    • beeplaced