Allow to use --config /path/to/config.js
to specify configuration file
This commit is contained in:
parent
5150204389
commit
18a517b7bf
4
NEWS.md
4
NEWS.md
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
Released 2016-mm-dd
|
Released 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:
|
Bug fixes:
|
||||||
- Allow to use absolute paths for log files #570.
|
- Allow to use absolute paths for log files #570.
|
||||||
|
|
||||||
|
34
app.js
34
app.js
@ -5,15 +5,30 @@ var fs = require('fs');
|
|||||||
|
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
|
|
||||||
var ENVIRONMENT;
|
var argv = require('yargs')
|
||||||
if ( process.argv[2] ) {
|
.usage('Usage: $0 <environment> [options]')
|
||||||
ENVIRONMENT = process.argv[2];
|
.help('h')
|
||||||
} else if ( process.env.NODE_ENV ) {
|
.example(
|
||||||
ENVIRONMENT = process.env.NODE_ENV;
|
'$0 production -c /etc/sql-api/config.js',
|
||||||
} else {
|
'start server in production environment with /etc/sql-api/config.js as config file'
|
||||||
ENVIRONMENT = 'development';
|
)
|
||||||
|
.alias('h', 'help')
|
||||||
|
.alias('c', 'config')
|
||||||
|
.nargs('c', 1)
|
||||||
|
.describe('c', 'Load configuration from path')
|
||||||
|
.argv;
|
||||||
|
|
||||||
|
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.environment = require(configurationFile);
|
||||||
|
var ENVIRONMENT = argv._[0] || process.env.NODE_ENV || global.environment.environment;
|
||||||
|
process.env.NODE_ENV = ENVIRONMENT;
|
||||||
|
|
||||||
// jshint undef:false
|
// jshint undef:false
|
||||||
var log = console.log.bind(console);
|
var log = console.log.bind(console);
|
||||||
var logError = console.error.bind(console);
|
var logError = console.error.bind(console);
|
||||||
@ -33,10 +48,6 @@ if (!availableEnvironments[ENVIRONMENT]){
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.env.NODE_ENV = ENVIRONMENT;
|
process.env.NODE_ENV = ENVIRONMENT;
|
||||||
|
|
||||||
// set environment specific variables
|
|
||||||
global.environment = require('./config/environments/' + ENVIRONMENT);
|
|
||||||
|
|
||||||
if (global.environment.uv_threadpool_size) {
|
if (global.environment.uv_threadpool_size) {
|
||||||
process.env.UV_THREADPOOL_SIZE = global.environment.uv_threadpool_size;
|
process.env.UV_THREADPOOL_SIZE = global.environment.uv_threadpool_size;
|
||||||
}
|
}
|
||||||
@ -99,6 +110,7 @@ var listener = server.listen(serverOptions.bind.port, serverOptions.bind.host, b
|
|||||||
var version = require("./package").version;
|
var version = require("./package").version;
|
||||||
|
|
||||||
listener.on('listening', function() {
|
listener.on('listening', function() {
|
||||||
|
log('Using configuration file "%s"', configurationFile);
|
||||||
log(
|
log(
|
||||||
"Windshaft tileserver %s started on %s:%s PID=%d (%s)",
|
"Windshaft tileserver %s started on %s:%s PID=%d (%s)",
|
||||||
version, serverOptions.bind.host, serverOptions.bind.port, process.pid, ENVIRONMENT
|
version, serverOptions.bind.host, serverOptions.bind.port, process.pid, ENVIRONMENT
|
||||||
|
932
npm-shrinkwrap.json
generated
932
npm-shrinkwrap.json
generated
File diff suppressed because it is too large
Load Diff
@ -39,7 +39,8 @@
|
|||||||
"step-profiler": "~0.3.0",
|
"step-profiler": "~0.3.0",
|
||||||
"turbo-carto": "0.16.0",
|
"turbo-carto": "0.16.0",
|
||||||
"underscore": "~1.6.0",
|
"underscore": "~1.6.0",
|
||||||
"windshaft": "2.5.0"
|
"windshaft": "2.5.0",
|
||||||
|
"yargs": "~5.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"istanbul": "~0.4.3",
|
"istanbul": "~0.4.3",
|
||||||
|
Loading…
Reference in New Issue
Block a user