-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (37 loc) · 1.05 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
const client = require("@mailchimp/mailchimp_marketing");
const express = require("express");
const request = require("request");
const app = express();
const path = require("path");
const port = 4000;
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, "public")));
client.setConfig({
apiKey: "fb84aa23c984c85c66939f891fda24bd-us21",
server: "us21",
});
const subscribeToEmail = async (email) => {
const response = await client.lists
.addListMember("22b4b152c7", {
email_address: email,
status: "subscribed",
})
.then((data) => {})
.catch((e) => {
console.log(e);
});
};
app.post("/api/subscription/", (req, res) => {
const { email, js } = req.body;
const mcData = JSON.stringify({
email_address: email,
status: "subscribed",
});
if (email) {
subscribeToEmail(email);
}
res.status(200).send();
res.end();
});
app.listen(port, () => console.log("Server is listening on port" + port));