-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
51 lines (44 loc) · 1.48 KB
/
server.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
49
50
51
require('dotenv').config();
var express = require('express');
var app = express();
var http = require('http').Server(app);
var bodyParser = require('body-parser');
var nodemailer = require('nodemailer');
var Airtable = require('airtable');
var base = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('appF6Zkc4Ro45xess');
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post('/signup', (req, res) => {
if (req.body.name === "") return res.redirect('/');
console.log(req.body.name + " signed up");
base('Signup').create({"Name": req.body.name}, function(err, record) {
if (err) { console.error(err); return; }
console.log("New Airtable record created: " + record.getId());
});
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'mattbstanciu@gmail.com',
pass: process.env.GMAIL_PASS
}
});
var mailOptions = {
from: 'mattbstanciu@gmail.com',
to: 'mattbstanciu@gmail.com',
subject: 'New Hack Club signup!',
text: req.body.name
};
transporter.sendMail(mailOptions, function(err, data) {
if (err) return console.log(err);
console.log("Email sent: " + data.response);
return res.redirect('/added');
});
});
app.get('/', function(request, response) {
response.sendFile(__dirname + '/index.html');
});
app.get('/added', (request, response) => {
response.sendFile(__dirname + '/added.html');
})
http.listen(3000);