Permalink
Browse files

Adds default configuration location for config file. (./config.js)

  • Loading branch information...
1 parent 7d015dd commit 42470f099716bf511f4d35c8d0e0c6b37e867eea @mdotterer mdotterer committed Mar 12, 2012
Showing with 34 additions and 12 deletions.
  1. +1 −1 .gitignore
  2. +33 −11 server.js
View
@@ -2,4 +2,4 @@ daemon.node/
lib/daemon.node
keys
node_modules
-
+config.js
View
@@ -28,28 +28,50 @@ if (config_path) {
throw new Error('The config file does not exist, so we can\'t be in secure mode. '
+ 'See the security section in the documentation for more details.');
}
-
+
var custom_config = require(config_path);
-
+
// Get the default values
- Config = require("./lib/juggernaut/config");
-
- // If the sharedToken has not been defined we throw
+ Config = require("./lib/juggernaut/config");
+
+ // If the sharedToken has not been defined we throw
// an error since is required in secure mode
if (!custom_config.sharedToken) {
throw new Error('The shared token must be defined. See the security section in '
+ 'the documentation for more details.');
}
-
- Config.sharedToken = custom_config.sharedToken;
-
+
+ Config.sharedToken = custom_config.sharedToken;
+
if (custom_config.expiration) {
- Config.expiration = custom_config.expiration;
+ Config.expiration = custom_config.expiration;
}
-
+
Config.secure_mode = true;
});
-}
+} else {
+ path.exists("./config.js", function(exists) {
+ if (exists) {
+ var custom_config = require("./config.js");
+ // Get the default values
+ Config = require("./lib/juggernaut/config");
+
+ // If the sharedToken has not been defined we throw
+ // an error since is required in secure mode
+ if (!custom_config.sharedToken && custom_config.secure_mode) {
+ throw new Error('The shared token must be defined. See the security section in '
+ + 'the documentation for more details.');
+ } else {
+ Config.sharedToken = custom_config.sharedToken;
+ }
+
+ if (custom_config.expiration) {
+ Config.expiration = custom_config.expiration;
+ }
+ Config.secure_mode = custom_config.secure_mode;
+ }
+ });
+}
Juggernaut = require("./index");
Juggernaut.listen(argv.port);

0 comments on commit 42470f0

Please sign in to comment.