-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
36 lines (30 loc) · 919 Bytes
/
app.js
File metadata and controls
36 lines (30 loc) · 919 Bytes
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
'use strict';
const express = require("express")
const mjml = require("mjml")
const fetch = require("node-fetch")
const pug = require("pug")
const _ = require("lodash")
var app = express();
app.set('views', './sources/email')
app.engine('pug', function (filePath, options, callback) { // define the template engine
var $ = pug.renderFile(filePath, options);
var html = mjml.mjml2html($);
// if (html.errors.length > 0) {
// return callback(html.errors, null);
// } else {
return callback(null, html.html);
// }
})
app.set('view engine', 'pug')
app.get('/email/:template', function (req, res) {
(async () => {
let event = await fetch(`https://devternity.com/js/event.js`)
let eventJson = await event.json()
let eventSelf = eventJson[0];
var data = {};
_.extend(data, eventSelf)
_.extend(data, req.query)
res.render(req.params.template + ".pug", data)
})();
})
app.listen(3000);