// dtp-webapp.js // Copryright (C) DTP Technologies, LLC // Licence: Apache-2.0 'use strict'; const DTP_COMPONENT_NAME = 'webapp'; require('dotenv').config(); const path = require('path'); const { SitePlatform, SiteLog } = require(path.join(__dirname, 'lib', 'site-lib')); module.rootPath = __dirname; module.pkg = require(path.join(module.rootPath, 'package.json')); module.config = { componentName: DTP_COMPONENT_NAME, root: module.rootPath, site: require(path.join(module.rootPath, 'config', 'site')), http: { address: process.env.HTTP_BIND_ADDRESS, port: parseInt(process.env.HTTP_BIND_PORT, 10), }, }; module.log = new SiteLog(module, module.config.componentName); module.shutdown = async ( ) => { }; (async ( ) => { process.on('unhandledRejection', (error, p) => { module.log.error('Unhandled rejection', { error: error, promise: p, stack: error.stack }); }); process.on('warning', (error) => { module.log.alert('warning', { error }); }); process.once('SIGINT', async ( ) => { module.log.info('SIGINT received'); module.log.info('requesting shutdown...'); await module.shutdown(); const exitCode = await SitePlatform.shutdown(); process.nextTick(( ) => { process.exit(exitCode); }); }); process.once('SIGUSR2', async ( ) => { await SitePlatform.shutdown(); process.kill(process.pid, 'SIGUSR2'); }); try { await SitePlatform.startPlatform(module); await SitePlatform.startWebServer(module); } catch (error) { module.log.error(`failed to start DTP ${DTP_COMPONENT_NAME}`, { error }); process.exit(-1); } })();