npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

socket-protect

v1.0.4

Published

Simple spam protection for socket.io 2.x

Downloads

10

Readme

socket-protect

Requirements

  • Nodejs v8.x
  • Socket.io v2.x

Installation

npm install socket-protect --save


Options

  • origin - {Array} - array of allowed origins. Default: [] - allow all
  • ipLimit- {Integer} - Number of allowed connections per ip. Default: 0
  • secure- {Boolean} - true if using https, false if http. Default: true
  • xdomain - {Boolean} - true - allow cross-domain. Default: false
  • debug - {Boolean}- set true to show debuggin messages. Default: false
  • login - {Object}
  • required - {Boolean} - true if authentication is required. Default: false
  • loginfn - {Function} - the authentication function that will return a Boolean callback. Default: noop()
  • timeout - {Number} - The time in ms, before socket is disconnected without authenticating. Default: 3000
  • ddos - {Object}
  • enabled - {Boolean} - Set true to enable rate limit on all connections. Default: true
  • timeout - {Number} - Time in ms that must be met before a connection is accepted. Default: 50
const defaultOpts = {
  origin: [],
  secure: true,
  xdomain: false,
  debug: false,
  ipLimit: 0,
  login: {
    required: false,
    loginfn: noop,
    timeout: 3000 // 3 seconds
  },
  ddos: {
    enabled: true,
    timeout: 50 // 50 ms
  }
};

API

  • protectHandshake {Function} - Used for protecting handshake between client and server
  • protectConnect {Function} - Specially used if options.login.required is true.

Example

const app = require('http').createServer(handler);
const io = require('socket.io')(app, {
  pingInterval: 10000,
  pingTimeout: 5000
});
const sp = require('socket-protect');

app.listen(8080, () => {
  console.log('Server listening to port ', 8080);
});

function handler(req, res) {
  res.writeHead(200);
  res.end('Hello World');
}

const auth = (socket, cb) => {
  socket.on('auth', () => {
    cb(true);
  });
};
const protectOpts = {
  origin: ['http://s.bitsler.com'],
  ipLimit: 4,
  secure: true,
  xdomain: true,
  debug: false,
  login: {
    required: true,
    loginfn: auth,
    timeout: 3000 // 3 seconds
  },
  ddos: {
    enabled: true,
    timeout: 500 // 500 ms
  }
};
io.use((socket, next) => {
  sp.protectHandshake(io, socket, protectOpts);
  next();
});
io.on('connection', socket => {
  sp.protectConnect(socket, protectOpts);

  // put your other events
  socket.on('message', data => {
    console.log(data);
  });
});