acebase-ipc-server
Version:
IPC Server that provides communication between isolated AceBase processes using the same database files, such as local pm2 and cloud-based clusters.
58 lines • 2.95 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const server_1 = require("./server");
// Usage: node start.js DBNAME=mydb HOST=localhost PORT=8585
//
function getVariable(name, defaultValue) {
// Checks if an argument with the name was passed, or if an environment variable was set with that name
// If not found, the default value will be used if one if provided. An error is raised otherwise.
name = name.toUpperCase();
const arg = process.argv.find(arg => arg.toUpperCase().startsWith(`${name}=`));
if (arg) {
return arg.split('=')[1];
}
if (typeof process.env[name] === 'string') {
return process.env[name];
}
if (typeof defaultValue === 'undefined') {
throw new Error(`No value for variable "${name}" found in environment or startup args`);
}
return defaultValue;
}
// const dbname = getVariable('DBNAME');
const host = getVariable('HOST', 'localhost');
const port = +getVariable('PORT', '9163'); // 9,16,3: IPC
const useSSL = getVariable('SSL', '0') === '1';
const keyPath = useSSL && getVariable('KEY_PATH', '') || undefined;
const certPath = useSSL && getVariable('CERT_PATH', '') || undefined;
const pfxPath = useSSL && getVariable('PFX_PATH', '') || undefined;
const passphrase = useSSL && getVariable('PASSPHRASE', '') || undefined;
const ssl = useSSL ? { keyPath, certPath, pfxPath, passphrase } : undefined;
const token = getVariable('TOKEN', '') || undefined;
const maxPayload = +getVariable('MAX_PAYLOAD', '0') || undefined;
(function start() {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
try {
const server = new server_1.AceBaseIPCServer({ host, port, ssl, token, maxPayload }); //dbname,
yield server.start();
if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_APP_INSTANCE) || ((_b = process.env) === null || _b === void 0 ? void 0 : _b.pm_id)) {
// Process was started by PM2, signal it's ready
process.send && process.send('ready');
}
}
catch (err) {
console.error(err);
}
});
})();
//# sourceMappingURL=start.js.map