@ones-op/node-host
Version:
ONES Open Platform Node.js plugin host
34 lines (33 loc) • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("./config");
const connect_1 = require("./connect");
const handler_1 = require("./handler");
const logger_1 = require("./logger");
const plugin_1 = require("./plugin");
const event_1 = require("./handler/event");
const instrumentation_1 = require("./instrumentation");
// NOTE: opentelemetry auto-instrumentations 需要用 node 的 `--require` 参数来提前加载 instrumentation.js
// 但 vercel/pkg 不支持,所以只能手动埋点
instrumentation_1.sdk.start();
const messageHandler = new handler_1.MessageHandler();
new connect_1.HttpServer(config_1.config.host.listen_port);
// OnEvent 的实现, 后续会用消息的方式实现, 这里应该去
(0, event_1.onEvent)();
// 本地启动
if (config_1.config.cli.debug_mode) {
logger_1.logger.info('Node-Host: Local Develop Mode');
}
process.on('uncaughtException', uncaughtExceptionHandler);
process.on('SIGTERM', async () => {
logger_1.logger.info('Handle SIGTERM, Call Plugin Stop...');
setTimeout(() => {
process.exit(0);
}, 3000);
plugin_1.pluginManager.destroyPlugin();
messageHandler.reportLog();
});
function uncaughtExceptionHandler(err) {
logger_1.logger.fatal('uncaughtException: ', err);
}
plugin_1.pluginManager.initPlugin(messageHandler);