forked from alainyog/JavaScript.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (28 loc) · 789 Bytes
/
index.js
File metadata and controls
32 lines (28 loc) · 789 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
var express = require('express');
var router = express.Router();
var path = require('path');
var bodyParser = require('body-parser');
var parseForm = bodyParser.urlencoded({ extended: false });
var mcapi = require('mailchimp-api');
mc = new mcapi.Mailchimp(process.env.MAILCHIMP_API);
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index');
});
/* POST subscribe an email to JS5 list. */
router.post('/subscribe', parseForm, function(req, res) {
mc.lists.subscribe(
{
id: process.env.LIST_ID,
email: {email:req.body.email},
double_optin: false,
send_welcome: true
},
function(data) {
res.json({data: data});
},
function(error) {
res.json({error: error});
});
});
module.exports = router;