12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #!/usr/bin/env node
- var path = require('path')
- , pkg = require('../package.json')
- , fs = require('fs')
- , version = pkg.version
- , app = require('express')()
- , PeerServer = require('../lib')
- , opts = require('optimist')
- .usage('Usage: $0')
- .options({
- debug: {
- demand: false,
- alias: 'd',
- description: 'debug',
- default: false
- },
- timeout: {
- demand: false,
- alias: 't',
- description: 'timeout (milliseconds)',
- default: 5000
- },
- ip_limit: {
- demand: false,
- alias: 'i',
- description: 'IP limit',
- default: 5000
- },
- concurrent_limit: {
- demand: false,
- alias: 'c',
- description: 'concurrent limit',
- default: 5000
- },
- key: {
- demand: false,
- alias: 'k',
- description: 'connection key',
- default: 'peerjs'
- },
- sslkey: {
- demand: false,
- description: 'path to SSL key'
- },
- sslcert: {
- demand: false,
- description: 'path to SSL certificate'
- },
- port: {
- demand: true,
- alias: 'p',
- description: 'port'
- },
- path: {
- demand: false,
- description: 'custom path'
- },
- allow_discovery: {
- demand: false,
- description: 'allow discovery of peers'
- }
- })
- .boolean('allow_discovery')
- .argv;
- opts.version = version;
- if (opts.sslkey && opts.sslcert) {
- opts['ssl'] = {};
- opts.ssl['key'] = fs.readFileSync(path.resolve(opts.sslkey));
- opts.ssl['certificate'] = fs.readFileSync(path.resolve(opts.sslcert));
- }
- process.on('uncaughtException', function(e) {
- console.error('Error: ' + e);
- });
- opts.server = app.listen(opts.port);
- app.use(PeerServer(opts));
- console.log(
- 'Started PeerServer, port: ' + opts.port + ', path: ' + (opts.path || '/') + (" (v. %s)"), version
- );
|