Sfoglia il codice sorgente

Add 'proxied' option for running the server behind a reverse proxy

lmb 10 anni fa
parent
commit
054145343e
2 ha cambiato i file con 18 aggiunte e 1 eliminazioni
  1. 12 0
      README.md
  2. 6 1
      lib/index.js

+ 12 - 0
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
 ### Combining with existing express app
 
 
 ```javascript
 ```javascript

+ 6 - 1
lib/index.js

@@ -15,7 +15,8 @@ function ExpressPeerServer(server, options) {
         key: 'peerjs',
         key: 'peerjs',
         ip_limit: 5000,
         ip_limit: 5000,
         concurrent_limit: 5000,
         concurrent_limit: 5000,
-        allow_discovery: false
+        allow_discovery: false,
+        proxied: false
     }, options);
     }, options);
 
 
     // Connected clients
     // Connected clients
@@ -27,6 +28,10 @@ function ExpressPeerServer(server, options) {
     // Mark concurrent users per ip
     // Mark concurrent users per ip
     app._ips = {};
     app._ips = {};
 
 
+    if (options.proxied) {
+        app.set('trust proxy', options.proxied);
+    }
+
     app.on('mount', function() {
     app.on('mount', function() {
         if (!server) {
         if (!server) {
             throw new Error('Server is not passed to constructor - '+
             throw new Error('Server is not passed to constructor - '+