Constructor
new PeerSoxServer(redisClient, options)
Parameters:
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
redisClient |
RedisClient |
The redis client to use for the store. |
||||||||||||||||||
options |
object |
Properties
|
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'
]
})
})