From 054145343e3b2b0b21365c9f5ecdd0b36133db16 Mon Sep 17 00:00:00 2001 From: lmb Date: Mon, 20 Oct 2014 10:16:54 +0100 Subject: [PATCH] Add 'proxied' option for running the server behind a reverse proxy --- README.md | 12 ++++++++++++ lib/index.js | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13f1201..e9a1f69 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,18 @@ var server = PeerServer({ }); ``` +#### Running PeerServer behind a reverse proxy + +Make sure to set the `proxied` option, otherwise IP based limiting will fail. +The option is passed verbatim to the +[expressjs `trust proxy` setting](http://expressjs.com/4x/api.html#app-settings) +if it is truthy. + +```javascript +var PeerServer = require('peer').PeerServer; +var server = PeerServer({port: 9000, path: '/myapp', proxied: true}); +``` + ### Combining with existing express app ```javascript diff --git a/lib/index.js b/lib/index.js index 480a3ff..dcb85b5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,7 +15,8 @@ function ExpressPeerServer(server, options) { key: 'peerjs', ip_limit: 5000, concurrent_limit: 5000, - allow_discovery: false + allow_discovery: false, + proxied: false }, options); // Connected clients @@ -27,6 +28,10 @@ function ExpressPeerServer(server, options) { // Mark concurrent users per ip app._ips = {}; + if (options.proxied) { + app.set('trust proxy', options.proxied); + } + app.on('mount', function() { if (!server) { throw new Error('Server is not passed to constructor - '+