-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
36 lines (25 loc) · 1.1 KB
/
index.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
const express = require('express')
const { validationMiddleware } = require('./src/middlewares')
const { PORT } = require('./src/config')
const { prepareMailsWithTemplate, parseSettings } = require('./src/pate')
const { sendEmails } = require('./src/mailer')
const app = express()
// https://stackoverflow.com/questions/19917401/error-request-entity-too-large
app.use(express.json({ limit: '50mb' }))
app.get('*', express.static('./public/'))
app.post('/preview', validationMiddleware, (req, res) => {
const { emails, template, settings } = req.body
const acualEmails = prepareMailsWithTemplate(emails, template, settings)
const exampleMail = acualEmails[0]
res.send({ html: exampleMail.html })
})
app.post('*', validationMiddleware, (req, res) => {
const { emails, template, settings } = req.body
const acualEmails = prepareMailsWithTemplate(emails, template, settings)
const { dryrun } = parseSettings(settings)
sendEmails(acualEmails, dryrun);
res.send('Payload accepted, check logs to see progress')
})
app.listen(PORT, () => {
console.log(`Pate listening at http://localhost:${PORT}`)
})