1
#!/usr/bin/env node
2

3 2
require('source-map-support').install()
4

5 2
import createApp from './app'
6 2
import { create as createLogger } from './common/log'
7

8 2
const log = createLogger('app')
9

10 2
export { createApp }
11

12 2
if (!module.parent) {
13 0
  const connector = createApp()
14 0
  connector.listen()
15
    .catch((err: any) => {
16 2
      const errInfo = (err && typeof err === 'object' && err.stack) ? err.stack : err
17 0
      log.error(errInfo)
18
    })
19

20 0
  let shuttingDown = false
21 0
  process.on('SIGINT', async () => {
22 0
    try {
23 2
      if (shuttingDown) {
24 0
        log.warn('received second SIGINT during graceful shutdown, exiting forcefully.')
25 0
        process.exit(1)
26 0
        return
27
      }
28

29 0
      shuttingDown = true
30

31
      // Graceful shutdown
32 0
      log.debug('shutting down.')
33 0
      await connector.shutdown()
34 0
      log.debug('completed graceful shutdown.')
35 0
      process.exit(0)
36
    } catch (err) {
37 2
      const errInfo = (err && typeof err === 'object' && err.stack) ? err.stack : err
38 0
      log.error('error while shutting down. error=%s', errInfo)
39 0
      process.exit(1)
40
    }
41
  })
42
}

Read our documentation on viewing source code .

Loading