Allow to use --config /path/to/config.js to specify configuration file

This commit is contained in:
Raul Ochoa 2016-09-15 00:36:24 +02:00
parent 510f1cd7d7
commit 27b73cb163
4 changed files with 362 additions and 12 deletions

View File

@ -1,6 +1,10 @@
1.35.0 - 2016-mm-dd
-------------------
New features:
* Allow to use `--config /path/to/config.js` to specify configuration file.
- Environment will be loaded from config file if `environment` key is present, otherwise it keeps current behaviour.
Bug fixes:
* Allow to use absolute paths for log files.

33
app.js
View File

@ -12,25 +12,39 @@
var fs = require('fs');
var path = require('path');
var ENV = process.env.NODE_ENV || 'development';
var argv = require('yargs')
.usage('Usage: $0 <environment> [options]')
.help('h')
.example(
'$0 production -c /etc/windshaft/config.js',
'start server in production environment with /etc/windshaft/config.js as configuration file'
)
.alias('h', 'help')
.alias('c', 'config')
.nargs('c', 1)
.describe('c', 'Load configuration from path')
.argv;
if (process.argv[2]) {
ENVIRONMENT = process.argv[2];
var environmentArg = argv._[0] || process.env.NODE_ENV || 'development';
var configurationFile = path.resolve(argv.config || './config/environments/' + environmentArg + '.js');
if (!fs.existsSync(configurationFile)) {
console.error('Configuration file "%s" does not exist', configurationFile);
process.exit(1);
}
global.settings = require(configurationFile);
var ENVIRONMENT = argv._[0] || process.env.NODE_ENV || global.settings.environment;
process.env.NODE_ENV = ENVIRONMENT;
var availableEnvironments = ['development', 'production', 'test', 'staging'];
// sanity check arguments
if (availableEnvironments.indexOf(ENVIRONMENT) === -1) {
console.error("\nnode app.js [environment]");
console.error("environments: " + availableEnvironments.join(', '));
console.error("node app.js [environment]");
console.error("Available environments: " + availableEnvironments.join(', '));
process.exit(1);
}
// set Node.js app settings and boot
global.settings = require('./config/environments/' + ENVIRONMENT);
global.settings.api_hostname = require('os').hostname().split('.')[0];
global.log4js = require('log4js');
@ -68,9 +82,10 @@ var version = require("./package").version;
var server = require('./app/server')();
server.listen(global.settings.node_port, global.settings.node_host, function() {
console.info('Using configuration file "%s"', configurationFile);
console.log(
"CartoDB SQL API %s listening on %s:%s with base_url %s PID=%d (%s)",
version, global.settings.node_host, global.settings.node_port, global.settings.base_url, process.pid, ENVIRONMENT
"CartoDB SQL API %s listening on %s:%s PID=%d (%s)",
version, global.settings.node_host, global.settings.node_port, process.pid, ENVIRONMENT
);
});

330
npm-shrinkwrap.json generated
View File

@ -237,6 +237,336 @@
"version": "1.6.0",
"from": "underscore@>=1.6.0 <1.7.0",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz"
},
"yargs": {
"version": "5.0.0",
"from": "yargs@>=5.0.0 <6.0.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-5.0.0.tgz",
"dependencies": {
"cliui": {
"version": "3.2.0",
"from": "cliui@>=3.2.0 <4.0.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz",
"dependencies": {
"strip-ansi": {
"version": "3.0.1",
"from": "strip-ansi@>=3.0.1 <4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"dependencies": {
"ansi-regex": {
"version": "2.0.0",
"from": "ansi-regex@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz"
}
}
},
"wrap-ansi": {
"version": "2.0.0",
"from": "wrap-ansi@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.0.0.tgz"
}
}
},
"decamelize": {
"version": "1.2.0",
"from": "decamelize@>=1.1.1 <2.0.0",
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz"
},
"get-caller-file": {
"version": "1.0.2",
"from": "get-caller-file@>=1.0.1 <2.0.0",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz"
},
"lodash.assign": {
"version": "4.2.0",
"from": "lodash.assign@>=4.2.0 <5.0.0",
"resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz"
},
"os-locale": {
"version": "1.4.0",
"from": "os-locale@>=1.4.0 <2.0.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
"dependencies": {
"lcid": {
"version": "1.0.0",
"from": "lcid@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz",
"dependencies": {
"invert-kv": {
"version": "1.0.0",
"from": "invert-kv@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz"
}
}
}
}
},
"read-pkg-up": {
"version": "1.0.1",
"from": "read-pkg-up@>=1.0.1 <2.0.0",
"resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz",
"dependencies": {
"find-up": {
"version": "1.1.2",
"from": "find-up@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz",
"dependencies": {
"path-exists": {
"version": "2.1.0",
"from": "path-exists@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz"
},
"pinkie-promise": {
"version": "2.0.1",
"from": "pinkie-promise@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
"dependencies": {
"pinkie": {
"version": "2.0.4",
"from": "pinkie@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz"
}
}
}
}
},
"read-pkg": {
"version": "1.1.0",
"from": "read-pkg@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz",
"dependencies": {
"load-json-file": {
"version": "1.1.0",
"from": "load-json-file@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"dependencies": {
"graceful-fs": {
"version": "4.1.6",
"from": "graceful-fs@>=4.1.2 <5.0.0",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.6.tgz"
},
"parse-json": {
"version": "2.2.0",
"from": "parse-json@>=2.2.0 <3.0.0",
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz",
"dependencies": {
"error-ex": {
"version": "1.3.0",
"from": "error-ex@>=1.2.0 <2.0.0",
"resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.0.tgz",
"dependencies": {
"is-arrayish": {
"version": "0.2.1",
"from": "is-arrayish@>=0.2.1 <0.3.0",
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz"
}
}
}
}
},
"pify": {
"version": "2.3.0",
"from": "pify@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz"
},
"pinkie-promise": {
"version": "2.0.1",
"from": "pinkie-promise@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
"dependencies": {
"pinkie": {
"version": "2.0.4",
"from": "pinkie@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz"
}
}
},
"strip-bom": {
"version": "2.0.0",
"from": "strip-bom@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz",
"dependencies": {
"is-utf8": {
"version": "0.2.1",
"from": "is-utf8@>=0.2.0 <0.3.0",
"resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz"
}
}
}
}
},
"normalize-package-data": {
"version": "2.3.5",
"from": "normalize-package-data@>=2.3.2 <3.0.0",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.3.5.tgz",
"dependencies": {
"hosted-git-info": {
"version": "2.1.5",
"from": "hosted-git-info@>=2.1.4 <3.0.0",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.1.5.tgz"
},
"is-builtin-module": {
"version": "1.0.0",
"from": "is-builtin-module@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz",
"dependencies": {
"builtin-modules": {
"version": "1.1.1",
"from": "builtin-modules@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz"
}
}
},
"semver": {
"version": "5.3.0",
"from": "semver@>=2.0.0 <3.0.0||>=3.0.0 <4.0.0||>=4.0.0 <5.0.0||>=5.0.0 <6.0.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz"
},
"validate-npm-package-license": {
"version": "3.0.1",
"from": "validate-npm-package-license@>=3.0.1 <4.0.0",
"resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz",
"dependencies": {
"spdx-correct": {
"version": "1.0.2",
"from": "spdx-correct@>=1.0.0 <1.1.0",
"resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-1.0.2.tgz",
"dependencies": {
"spdx-license-ids": {
"version": "1.2.2",
"from": "spdx-license-ids@>=1.0.2 <2.0.0",
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz"
}
}
},
"spdx-expression-parse": {
"version": "1.0.3",
"from": "spdx-expression-parse@>=1.0.0 <1.1.0",
"resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-1.0.3.tgz"
}
}
}
}
},
"path-type": {
"version": "1.1.0",
"from": "path-type@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz",
"dependencies": {
"graceful-fs": {
"version": "4.1.6",
"from": "graceful-fs@>=4.1.2 <5.0.0",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.6.tgz"
},
"pify": {
"version": "2.3.0",
"from": "pify@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz"
},
"pinkie-promise": {
"version": "2.0.1",
"from": "pinkie-promise@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
"dependencies": {
"pinkie": {
"version": "2.0.4",
"from": "pinkie@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz"
}
}
}
}
}
}
}
}
},
"require-directory": {
"version": "2.1.1",
"from": "require-directory@>=2.1.1 <3.0.0",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz"
},
"require-main-filename": {
"version": "1.0.1",
"from": "require-main-filename@>=1.0.1 <2.0.0",
"resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz"
},
"set-blocking": {
"version": "2.0.0",
"from": "set-blocking@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz"
},
"string-width": {
"version": "1.0.2",
"from": "string-width@>=1.0.2 <2.0.0",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"dependencies": {
"code-point-at": {
"version": "1.0.0",
"from": "code-point-at@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.0.0.tgz",
"dependencies": {
"number-is-nan": {
"version": "1.0.0",
"from": "number-is-nan@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.0.tgz"
}
}
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"from": "is-fullwidth-code-point@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"dependencies": {
"number-is-nan": {
"version": "1.0.0",
"from": "number-is-nan@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.0.tgz"
}
}
},
"strip-ansi": {
"version": "3.0.1",
"from": "strip-ansi@>=3.0.1 <4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"dependencies": {
"ansi-regex": {
"version": "2.0.0",
"from": "ansi-regex@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz"
}
}
}
}
},
"which-module": {
"version": "1.0.0",
"from": "which-module@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/which-module/-/which-module-1.0.0.tgz"
},
"window-size": {
"version": "0.2.0",
"from": "window-size@>=0.2.0 <0.3.0",
"resolved": "https://registry.npmjs.org/window-size/-/window-size-0.2.0.tgz"
},
"y18n": {
"version": "3.2.1",
"from": "y18n@>=3.2.1 <4.0.0",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz"
},
"yargs-parser": {
"version": "3.2.0",
"from": "yargs-parser@>=3.2.0 <4.0.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-3.2.0.tgz",
"dependencies": {
"camelcase": {
"version": "3.0.0",
"from": "camelcase@>=3.0.0 <4.0.0",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-3.0.0.tgz"
}
}
}
}
}
}
}

View File

@ -32,7 +32,8 @@
"step": "~0.0.5",
"step-profiler": "~0.3.0",
"topojson": "0.0.8",
"underscore": "~1.6.0"
"underscore": "~1.6.0",
"yargs": "~5.0.0"
},
"devDependencies": {
"istanbul": "~0.4.2",