Permalink
Browse files

use jsconfig

  • Loading branch information...
1 parent 1ce415c commit bb5f7f55a3821c8fe6a9830792dc3081eb3a0e39 @dodo dodo committed Dec 12, 2011
Showing with 42 additions and 8 deletions.
  1. +12 −0 config.default.js
  2. +1 −0 package.json
  3. +29 −8 xmpp-server.js
View
@@ -0,0 +1,12 @@
+module.exports = {
+ port: 5222,
+ domain: 'localhost',
+
+ // logging
+ logger: false,
+
+ //tls: {
+ // keyPath: '/etc/xmpp-server/tls/localhost-key.pem',
+ // certPath: '/etc/xmpp-server/tls/localhost-cert.pem'
+ //},
+};
View
@@ -10,6 +10,7 @@
"redis": ">=0.7.1",
"websocket": ">=0.0.19",
"ltx": ">=0.1.1",
+ "jsconfig": ">=0.1.1",
"winston": ">=0.5.8"
},
"repositories": [{
View
@@ -1,15 +1,36 @@
#!/usr/bin/env node
-if(process.argv.length === 2) {
- console.log("Please provide a path to a config path.");
- process.exit(1);
-}
+var path = require('path'),
+ config = require('jsconfig'),
+ defaultConfigPath = path.join(__dirname, "config.default.js");
+config.defaults(defaultConfigPath);
-var configuration = require(process.argv[process.argv.length -1]);
+// environment parameters
+config.set('env', {
+ DOMAIN: 'domain',
+ PORT: ['port', parseInt],
+});
+
+config.cli({
+ domain: ['domain', ['d', "xmpp server domain", 'host']],
+ port: ['port', ['p', "xmpp server port", 'number']],
+ config: ['c', "load config file", 'path', defaultConfigPath],
+ logger: ['logger', [false, "Log to stdout"]],
+});
+
+config.load(function (args, opts) {
+
+ // preserve the old api with loading a config file from argv
+ if(args.length > 0)
+ opts.config = args[args.length - 1];
+
+ if(opts.config !== defaultConfigPath)
+ config.merge(require(opts.config));
-var server = require('./lib/server.js');
-server.run(configuration.config, function() {
- // Server ready!
+ var server = require('./lib/server.js');
+ server.run(config, function() {
+ // Server ready!
+ });
});

0 comments on commit bb5f7f5

Please sign in to comment.