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) { module.exports = function(argv) {
var SocketCluster = require('socketcluster').SocketCluster; var SocketCluster = require('socketcluster').SocketCluster;
var options = assign(getOptions(argv), {
return new SocketCluster({
host: argv.hostname || process.env.npm_package_remotedev_hostname || null,
port: Number(argv.port || process.env.npm_package_remotedev_port) || 8000,
workerController: __dirname + '/worker.js', workerController: __dirname + '/worker.js',
allowClientPublish: false, 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
}
}); });
return new SocketCluster(options);
}; };

View File

@ -30,6 +30,7 @@
"ejs": "^2.4.1", "ejs": "^2.4.1",
"express": "^4.13.3", "express": "^4.13.3",
"minimist": "^1.2.0", "minimist": "^1.2.0",
"object-assign": "^4.1.0",
"socketcluster": "^4.3.1" "socketcluster": "^4.3.1"
} }
} }