-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
104 lines (73 loc) · 2.54 KB
/
server.js
File metadata and controls
104 lines (73 loc) · 2.54 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var express = require('express');
var app = express();
var path = require('path');
var contact_confirmation = require('./lib/contact_confirmation.js');
var contact_information = require('./lib/contact_information.js');
var contact_register = require('./lib/contact_register.js')
var mailchimp = require('./lib/mailchimp.js')
const bodyParser = require('body-parser');
const util = require('util')
var router = express.Router();
var app = express()
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers',
'Content-Type, Authorization, Content-Length, X-Requested-With');
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.send(200);
} else {
next();
}
};
var logger = function(req, res, next) {
next();
}
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.post('/hook', (req, res) => {
console.log("req body:")
var datetime = new Date();
console.log(datetime);
// console.log(util.inspect(req.body, false, null))
contact_register(req.body.form_response.answers[1].email, function() {
console.log(req.body.form_response.answers[1].email +
" has successfully registered for inventure")
})
mailchimp(req.body.form_response.answers[1].email, function(err) {
if (err !== null) {
console.log("error, not added to mailing list")
}
console.log("mail succesfully sent to mailchimp", req.body.form_response
.answers[1].email);
})
res.json(req.body.form_response.answers[1].email);
});
app.get('/api/mail', (req, res) => {
var host = req.headers.host;
var origin = req.headers.origin
console.log("req query", req.query)
contact_confirmation(req.query.email, function() {
console.log("auto response to client succesfully sent");
contact_information("eddie.ren.2013@gmail.com", req.query.email,
req.query.name, req.query.message,
function() {
console.log("mail succesfully sent to eddie");
contact_information("malindu@meetinventure.com", req.query.email,
req.query.name, req.query.message,
function() {
console.log("mail succesfully sent to malindu");
});
});
});
res.redirect('https://meetinventure.com/contact.html');
});
app.use(logger);
app.use(express.static(path.join(__dirname, 'build')));
// app.use(allowCrossDomain);
app.listen(3000, function() {
console.log('server stared on port 3000')
});