CartoDB-SQL-API/metro/index.js

41 lines
909 B
JavaScript
Raw Normal View History

'use strict';
const metro = require('./metro');
const path = require('path');
const fs = require('fs');
const { CONFIG_PATH = path.resolve(__dirname, './config.json') } = process.env;
const existsConfigFile = fs.existsSync(CONFIG_PATH);
2020-07-01 01:41:36 +08:00
if (!existsConfigFile) {
exit(4)(new Error(`Wrong path for CONFIG_PATH env variable: ${CONFIG_PATH} no such file`));
}
2020-07-01 01:41:36 +08:00
let config;
2020-07-01 01:41:36 +08:00
if (existsConfigFile) {
config = fs.readFileSync(CONFIG_PATH);
try {
config = JSON.parse(config);
} catch (e) {
exit(5)(new Error('Wrong config format: invalid JSON'));
2020-07-01 01:41:36 +08:00
}
}
metro({ metrics: config && config.metrics })
.then(exit(0))
.catch(exit(1));
process.on('uncaughtException', exit(2));
process.on('unhandledRejection', exit(3));
function exit (code = 1) {
return function (err) {
if (err) {
console.error(err);
}
2020-07-01 01:41:36 +08:00
process.exit(code);
};
}