-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (38 loc) · 1.13 KB
/
app.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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
require('dotenv').config()
// Middleware telling Express to serve files from the public folder
app.use(express.static(__dirname + '/public'));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
app.listen(3000, function() {
console.log("Listening on Andre 3000")
});
app.post('/', function(req, res) {
addEmailToMailchimp(req.body.email);
res.end('success!!!');
} );
function addEmailToMailchimp(email) {
var request = require("request");
var options = {
method: 'POST',
url: process.env.MAILCHIMP_LIST,
headers: {
'postman-token': process.env.POSTMAN_TOKEN,
'cache-control': 'no-cache',
authorization: ''
},
body: {
email_address: email,
status: 'subscribed'
},
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
}