Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

storj-service-middleware

Package Overview
Dependencies
Maintainers
7
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storj-service-middleware

common middleware for various storj services

  • 1.3.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
7
Created
Source

Storj Service Middleware

Common Express middleware for various Storj services.

$ npm install storj-service-middleware --save
var Storage = require('storj-service-storage-models');
var db = new Storage({ /* config */ });
var middleware = require('storj-service-middleware');
var app = require('express')();

app.use(middleware.authenticate(db));
app.use(middleware.errorhandler());

Rate Limiter

Instantiate the rate limiter with a redis client client and your express app app

const app = express();
const client = require('redis').createClient();
const limiter = middleware.rateLimiter(client);

Then, you can use limiter as middleware and pass it an options object.

app.get('/route', limiter({
  lookup: function(req) {
    return [req.user._id, req.connection.remoteAddress]
  },
  onRateLimited: function(req, res, next) {
    log.info('user rate limited', req.user);
    return next(new errors.BadRequestError('Slow down, dude.'));
  },
  total: 150,
  expire: 1000 * 60 // 150 requests a minute allowed
  }), function(req, res) {
  res.status(200).send('hello');
});

Testing

Redis must be running for the tests to work. The easiest way to get an instance running is via Docker.

$ docker run --name redis -p 6379:6379 -d redis

Then, npm test will kick off the test suite for you.

License

Credit for much of the rate limiter code goes to https://github.com/juliendangers/express-limiter2 released under the MIT license.

All other code released under AGPLv3.

Keywords

FAQs

Package last updated on 21 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc