update README
This commit is contained in:
parent
6f509b848c
commit
86882a74f0
93
README.md
93
README.md
@ -4,111 +4,48 @@
|
||||
|
||||
PeerServer helps broker connections between PeerJS clients. Data is not proxied through the server.
|
||||
|
||||
## [http://peerjs.com](http://peerjs.com)
|
||||
## [https://peerjs.com](https://peerjs.com)
|
||||
|
||||
### Run PeerServer
|
||||
|
||||
Install the library:
|
||||
|
||||
1. Clone app:
|
||||
```bash
|
||||
$> npm install peer
|
||||
$> git clone https://github.com/peers/peerjs-server.git
|
||||
```
|
||||
|
||||
Run the server:
|
||||
|
||||
2. Install dependencies:
|
||||
```bash
|
||||
$> peerjs --port 9000 --key peerjs
|
||||
$> npm install
|
||||
```
|
||||
|
||||
Or, create a custom server:
|
||||
|
||||
```javascript
|
||||
var PeerServer = require('peer').PeerServer;
|
||||
var server = PeerServer({port: 9000, path: '/myapp'});
|
||||
3. Run the server:
|
||||
```bash
|
||||
$> node ./src/index.js --port 9000 --path /myapp
|
||||
```
|
||||
|
||||
Connecting to the server from PeerJS:
|
||||
|
||||
```html
|
||||
<script>
|
||||
// No API key required when not using cloud server
|
||||
var peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
|
||||
const peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
|
||||
</script>
|
||||
```
|
||||
|
||||
Using HTTPS: Simply pass in PEM-encoded certificate and key.
|
||||
Using HTTPS: Simply pass in paths to PEM-encoded certificate and key.
|
||||
|
||||
```javascript
|
||||
var fs = require('fs');
|
||||
var PeerServer = require('peer').PeerServer;
|
||||
|
||||
var server = PeerServer({
|
||||
port: 9000,
|
||||
ssl: {
|
||||
key: fs.readFileSync('/path/to/your/ssl/key/here.key'),
|
||||
cert: fs.readFileSync('/path/to/your/ssl/certificate/here.crt')
|
||||
}
|
||||
});
|
||||
```bash
|
||||
$> node ./src/index.js --port 9000 --path /myapp --sslKeyPath /path/to/your/ssl/key/here.key --sslCertPath /path/to/your/ssl/certificate/here.crt
|
||||
```
|
||||
|
||||
#### Running PeerServer behind a reverse proxy
|
||||
|
||||
Make sure to set the `proxied` option, otherwise IP based limiting will fail.
|
||||
Make sure to set the `proxied` option.
|
||||
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
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
var ExpressPeerServer = require('peer').ExpressPeerServer;
|
||||
|
||||
app.get('/', function(req, res, next) { res.send('Hello world!'); });
|
||||
|
||||
// =======
|
||||
|
||||
var server = app.listen(9000);
|
||||
|
||||
var options = {
|
||||
debug: true
|
||||
}
|
||||
|
||||
var peerserver = ExpressPeerServer(server, options);
|
||||
|
||||
app.use('/api', peerserver);
|
||||
|
||||
// == OR ==
|
||||
|
||||
var server = require('http').createServer(app);
|
||||
var peerserver = ExpressPeerServer(server, options);
|
||||
|
||||
app.use('/peerjs', peerserver);
|
||||
|
||||
server.listen(9000);
|
||||
|
||||
// ========
|
||||
```
|
||||
|
||||
### Events
|
||||
|
||||
The `'connection'` event is emitted when a peer connects to the server.
|
||||
|
||||
```javascript
|
||||
peerserver.on('connection', function(id) { ... });
|
||||
```
|
||||
|
||||
The `'disconnect'` event is emitted when a peer disconnects from the server or
|
||||
when the peer can no longer be reached.
|
||||
|
||||
```javascript
|
||||
peerserver.on('disconnect', function(id) { ... });
|
||||
```bash
|
||||
$> node ./src/index.js --port 9000 --path /myapp --proxied true
|
||||
```
|
||||
|
||||
## Problems?
|
||||
|
@ -1,10 +1,24 @@
|
||||
const convict = require('convict');
|
||||
|
||||
module.exports = convict({
|
||||
debug: {
|
||||
doc: 'Enable debug mode',
|
||||
format: Boolean,
|
||||
default: false
|
||||
logger: {
|
||||
level: {
|
||||
doc: 'The log level. See log4js',
|
||||
format: [
|
||||
'ALL',
|
||||
'MARK',
|
||||
'TRACE',
|
||||
'DEBUG',
|
||||
'INFO',
|
||||
'WARN',
|
||||
'ERROR',
|
||||
'FATAL',
|
||||
'OFF'
|
||||
],
|
||||
default: 'ERROR',
|
||||
env: 'LOG_LEVEL',
|
||||
arg: 'logLevel'
|
||||
}
|
||||
},
|
||||
env: {
|
||||
doc: 'The application environment.',
|
||||
@ -27,27 +41,35 @@ module.exports = convict({
|
||||
key: {
|
||||
doc: 'The key to check incoming clients',
|
||||
format: String,
|
||||
default: 'peerjs'
|
||||
default: 'peerjs',
|
||||
env: 'APP_KEY',
|
||||
arg: 'key'
|
||||
},
|
||||
path: {
|
||||
doc: '',
|
||||
format: String,
|
||||
default: '/myapp'
|
||||
default: '/myapp',
|
||||
env: 'APP_PATH',
|
||||
arg: 'path'
|
||||
},
|
||||
concurrent_limit: {
|
||||
doc: 'Max connections',
|
||||
format: 'duration',
|
||||
default: 5000
|
||||
default: 5000,
|
||||
arg: 'concurrentLimit'
|
||||
},
|
||||
allow_discovery: {
|
||||
doc: 'Allow discovery of peers',
|
||||
format: Boolean,
|
||||
default: false
|
||||
default: false,
|
||||
arg: 'allowDiscovery'
|
||||
},
|
||||
proxied: {
|
||||
doc: 'Set true if server running behind proxy',
|
||||
format: Boolean,
|
||||
default: false
|
||||
default: false,
|
||||
env: 'APP_PROXIED',
|
||||
arg: 'proxied'
|
||||
},
|
||||
cleanup_out_msgs: {
|
||||
doc: '',
|
||||
@ -58,12 +80,14 @@ module.exports = convict({
|
||||
key_path: {
|
||||
doc: 'The path to the private key file',
|
||||
format: String,
|
||||
default: ''
|
||||
default: '',
|
||||
arg: 'sslKeyPath'
|
||||
},
|
||||
cert_path: {
|
||||
doc: 'The path to the cert file',
|
||||
format: String,
|
||||
default: ''
|
||||
default: '',
|
||||
arg: 'sslCertPath'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,6 +1,8 @@
|
||||
const log4js = require('log4js');
|
||||
const config = require('../../../config');
|
||||
|
||||
const logger = log4js.getLogger();
|
||||
logger.level = 'ALL';
|
||||
|
||||
logger.level = config.get('logger.level');
|
||||
|
||||
module.exports = logger;
|
||||
|
Loading…
x
Reference in New Issue
Block a user