PeerSoxServer

PeerSoxServer

The server manages the generation and validation of pairing codes and hashes. They are stored in redis, for local development redis-mock is used.

Generated Pairings are only valid for a short amount of time. If they are not validated in that time slot, they are deleted. If they are validated, the code is removed from redis, while the hash's expire time is increased.

Constructor

new PeerSoxServer(redisClient, options)

Parameters:
Name Type Description
redisClient RedisClient

The redis client to use for the store.

options object
Properties
Name Type Description
app object

An existing express app.

server object

An existing http server.

port number

The port on which the server should run.

middleware array

Additional middleware for use in express.

allowOrigins array

List of origins for which a connection is allowed.

Source:
Examples

Minimal

// Start a server on port 3000, using redis-mock for storage.
// This is not meant for production use.

const PeerSoxServer = require('peersox/lib/peersox.server.js').default
new PeerSoxServer()

Redis server with express-bruteforce

// Connect and use a redis server for storage and provide an express
// middleware that prevents brute force attacks on the server.

const PeerSoxServer = require('peersox/lib/peersox.server.js').default
const ExpressBrute = require('express-brute')
const redis = require('redis')
const BruteRedis = require('express-brute-redis')

// Create a new redis client.
const redisClient = redis.createClient('//localhost:6379')

// Init the PeerSox server when the redis client is ready.
redisClient.on('ready', function () {
  console.log('Connected to Redis at')

  // Use the redis client as the store for express-brute.
  const bruteStore = new BruteRedis({
    client: redisClient
  })

  // Instantiate the express-brute middleware.
  const bruteforce = new ExpressBrute(bruteStore, {
    freeRetries: 20
  })

  // Instantiate the PeerSox server.
  new PeerSoxServer({
    storage: redisClient,
    middleware: [
      bruteforce.prevent
    ],
    allowOrigins: [
      'http://localhost:8080',
      'https://example.com'
    ]
  })
})

Classes

PeerSoxServer