GithubHelp home page GithubHelp logo

node-requests-jail's Introduction

node-requests-jail

Build Status

Introduction

node-requests-jail is a middleware which stores requests until its "unleash" method is called.

Usage

The module receives 2 parameters:

  1. express application (mandatory): initialized by app = express();
  2. an "options" object (optional) which contains the following key-value pair: {match: } The request's path will be matched against the regexp pattern. When a match is detected the request will be delayed.

The following example demonstrates usage of requests-jail. In this case all the requests are delayed by the requests-jail middleware until some "longAction" finishes and the middleware's unleash method is called.

var express = require('express');
app = express();
var reqJail = require('node-requests-jail')(app);

app.use(express.bodyParser());
app.use(reqJail);
app.listen(5000);

app.get('/', function(req, res) {
  res.send('Hello from root', 200);
});

//Long action that must finish before requests are released.
longAction(function(err) {
  console.info("long action is done");
  reqJail.unleash();
});

The following example demonstrates usage of requests-jail with the optional 'match' parameter. In this example the match value is a regular expression which matches each path which is not the root path. In this case all the requests will be delayed by the requests-jail middleware except requests with path = '/'

var express = require('express');
app = express();
var reqJail = require('node-requests-jail')(app, {match: /^(?!\/$)/});

app.use(express.bodyParser());
app.use(reqJail);
app.listen(5000);

app.get('/', function(req, res) {
  res.send('Hello from root', 200);
});

app.get('/name', function(req, res) {
  res.send('Hello from name page', 200);
});

//Long action that must finish before requests are released.
longAction(function(err) {
  console.info("long action is done");
  reqJail.unleash();
});

License

MIT

node-requests-jail's People

Contributors

lilachp avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.