Initial commit
This commit is contained in:
40
server/src/email/index.js
Normal file
40
server/src/email/index.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import config from 'config'
|
||||
import pino from 'pino'
|
||||
import * as pinoExpress from 'pino-pretty-express'
|
||||
import createError from 'http-errors'
|
||||
import { MS } from '../message-service'
|
||||
import { EmailHandlers } from './EmailHandlers'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
const serviceName = 'dar-email'
|
||||
const isProduction = (process.env.NODE_ENV == 'production')
|
||||
let log = null
|
||||
|
||||
if (isProduction) {
|
||||
log = pino( { name: serviceName },
|
||||
fs.createWriteStream(path.join(config.get('logDir'), serviceName + '.log'))
|
||||
)
|
||||
} else {
|
||||
const pretty = pinoExpress.pretty({})
|
||||
pretty.pipe(process.stdout)
|
||||
log = pino({ name: serviceName }, pretty)
|
||||
}
|
||||
|
||||
const ms = new MS(serviceName, { durable: true }, log)
|
||||
let container = { ms, log }
|
||||
|
||||
const amqpUri = config.get('uri.amqp')
|
||||
|
||||
ms.connect(amqpUri).then(() => {
|
||||
log.info(`Connected to RabbitMQ at ${amqpUri}`)
|
||||
|
||||
container = {
|
||||
...container,
|
||||
handlers: new EmailHandlers(container)
|
||||
}
|
||||
|
||||
ms.listen(container.handlers)
|
||||
}).catch((err) => {
|
||||
log.error(isProduction ? err.message : err)
|
||||
})
|
||||
Reference in New Issue
Block a user