-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
61 lines (53 loc) · 1.85 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
52
53
54
55
56
57
58
59
60
61
/**
* General setup of the web application.
* Import express and other stand libraries
* to get up and running.
*/
require('dotenv').config();
var express = require('express'),
path = require('path'),
bodyParser = require('body-parser'),
app = express();
var nodemailer = require('nodemailer');
var sparkPostTransport = require('nodemailer-sparkpost-transport');
var transporter = nodemailer.createTransport(sparkPostTransport({sparkPostApiKey: process.env.SPARKPOST_API_KEY}))
/**
* Set EJS template Engine
* EJS let's us use variables in-line
* with our markup and renders it to HTML
* for us.
*/
// app.set('views','./views');
// app.set('view engine','ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({ extended: true })); //support x-www-form-urlencoded
app.use(bodyParser.json());
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || 'localhost');
app.disable('x-powered-by');
app.get('/', function(req, res) {
res.send('index.html');
});
app.post('/contact', function(req, res) {
transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'New Message From 1617 Website',
text: '',
html: 'New message from the 1617 website: <br/>' +
'Name: ' + req.body.name + '<br/>' +
'E-mail: ' + req.body.email + '<br/>' +
'Subject: ' + req.body.subject + '<br/>' +
'Message: ' + req.body.body + '<br/>'
}, function(err, info) {
if (err) {
console.log('Error: ' + err);
res.send(401, 'There was a problem sending your email.')
} else {
res.send(200);
}
});
});
app.listen(app.get('port'), app.get('host'), function() {
console.log('1617BarberLife.com has started listening at http://' + app.get('host') + ':' + app.get('port') + '. ^C to stop.');
});