/
main.js
62 lines (45 loc) · 1.37 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import path from 'path'
import Mali from 'mali'
import nodemailer from 'nodemailer'
import { service } from 'grpc-health-check'
import logger from './logger'
import HealthCheckService from './services/health-check.service'
import MailerClientService from './services/mailer.service'
const SERVICE_NAME = 'MailerService'
const SERVICE_PROTO = path.resolve(__dirname, '_proto/mailer.proto')
const HOST_PORT = `${process.env.HOST}:${process.env.PORT}`
const main = async () => {
const transporter = nodemailer.createTransport({
pool: true,
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: process.env.SMTP_SECURE,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
})
const mailerClient = new MailerClientService(transporter, logger, SERVICE_NAME)
const MailerService = {
send: mailerClient.send.bind(mailerClient)
}
const app = new Mali()
const healthCheckService = new HealthCheckService(SERVICE_NAME)
const healthCheckImpl = await healthCheckService.getServiceImpl()
app.addService(SERVICE_PROTO, null, {
enums: String,
objects: true,
arrays: true
})
app.addService(service)
app.use({
MailerService,
...healthCheckImpl
})
await app.start(HOST_PORT)
logger.info(`gRPC Server is now listening on port ${process.env.PORT}`)
return {
app
}
}
export default main