-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1.01 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
37
38
39
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
require('@google-cloud/debug-agent').start({ allowExpressions: true });
app.use(bodyParser.json());
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log('Listening on port', port);
});
app.get('/', async (req, res) => {
console.log(`Email Service: health check`);
res.status(200).send('Health check..');
})
app.post('/', async (req, res) => {
const notification = decodeBase64Json(req.body.message.data);
try
{
console.log(`Email Service: Report ${notification.id} trying...`);
sendEmail();
console.log(`Email Service: Report ${notification.id} success :-)`);
res.status(204).send();
}
catch (ex) {
console.log(`Email Service: Report ${notification.id} failure: ${ex}`);
res.status(500).send();
}
})
function decodeBase64Json(data) {
return JSON.parse(Buffer.from(data, 'base64').toString());
}
function sendEmail() {
console.log('Sending email');
}