-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
57 lines (39 loc) · 1.28 KB
/
index.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
52
53
54
55
56
57
var express = require('express');
var path = require('path');
var app = express();
var bodyParser = require('body-parser');
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
app.set('port', (process.env.PORT || 5000));
app.use(express.static('public'));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/main.html'));
});
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
// views is directory for all template files
// app.set('views', __dirname + '/views');
// app.set('view engine', 'ejs');
// app.get('/', function(request, response) {
// response.render('pages/index')
// });
// app.get('/cool', function(request, response) {
// response.send(cool());
// });
// Email engine
app.post('/email', function(request, response) {
console.log('O que vei', request.body);
const email = request.body.email;
const message = request.body.message;
const msg = {
to: '[email protected]',
from: email,
subject: 'Danilo Aleixo | Personal Website',
text: message
};
sgMail.send(msg);
response.sendStatus(200);
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});