Split options to another file

This commit is contained in:
Jhen
2016-07-19 00:02:04 +08:00
parent e915a2ff9c
commit 342878f787
3 changed files with 19 additions and 11 deletions

12
bin/getOptions.js Normal file
View File

@ -0,0 +1,12 @@
module.exports = function getOptions(argv) {
return {
host: argv.hostname || process.env.npm_package_remotedev_hostname || null,
port: Number(argv.port || process.env.npm_package_remotedev_port) || 8000,
protocol: argv.protocol || process.env.npm_package_remotedev_protocol || 'http',
protocolOptions: !(argv.protocol === 'https') ? null : {
key: argv.key || process.env.npm_package_remotedev_key || null,
cert: argv.cert || process.env.npm_package_remotedev_cert || null,
passphrase: argv.passphrase || process.env.npm_package_remotedev_passphrase || null
}
};
}

View File

@ -1,16 +1,11 @@
var assign = require('object-assign');
var getOptions = require('./getOptions');
module.exports = function(argv) {
var SocketCluster = require('socketcluster').SocketCluster;
return new SocketCluster({
host: argv.hostname || process.env.npm_package_remotedev_hostname || null,
port: Number(argv.port || process.env.npm_package_remotedev_port) || 8000,
var options = assign(getOptions(argv), {
workerController: __dirname + '/worker.js',
allowClientPublish: false,
protocol: argv.protocol || process.env.npm_package_remotedev_protocol || 'http',
protocolOptions: !(argv.protocol === 'https') ? null : {
key: argv.key || process.env.npm_package_remotedev_key || null,
cert: argv.cert || process.env.npm_package_remotedev_cert || null,
passphrase: argv.passphrase || process.env.npm_package_remotedev_passphrase || null
}
allowClientPublish: false
});
return new SocketCluster(options);
};