-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
78 lines (60 loc) · 1.97 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const express = require('express');
//return express app
const app = express();
//middleware
app.use(express.static('public'));
var bodyParser = require('body-parser');
app.use(bodyParser.json());
const nodemailer = require('nodemailer');
const xoauth2 = require('xoauth2');
//HANDLE PAGE REQS
//dum google page
app.get('/google495c73f1f9c05beb.html', function(req, res){
res.sendFile(__dirname + '/google495c73f1f9c05beb.html')
});
//root page
app.get(['/', '/index.html'], function(req, res){
res.sendFile(__dirname + '/public/index-1.html')
});
//download request
app.get('/downloadcv', function(req, res){
var file = __dirname + '/public/downloads/JamesMurphyCV.pdf';
res.download(file); // Set disposition and send it.
});
//NODEMAILER/CONTACT FORM
app.post('/contact', function(req, res){
console.log(req.body); // parsed to JS object
res.send(JSON.stringify(req.body)); //just bounce json right back
//generate email
let transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false, //true for 465 only
auth: {
user: '[email protected]',
pass: ''
}
});
const mailOptions = {
from: '"Administrator" <[email protected]>', // sender address
to: '[email protected]', // list of receivers
subject: "Someone has messaged your website", // Subject line
html: "<p>Name: " + req.body.fullName + "<br>Email: " + req.body.email + "<br>Message: " + req.body.msg + "</p>"
};
transporter.sendMail(mailOptions, function (err, info) {
console.log("got this far")
if(err)
console.log(err)
else
console.log(info.messageId);
});
});
//activate server
app.listen(80, '192.241.220.140', function(){
console.log('App listening on port 80');
});
/*
app.listen(8080, '127.0.0.1', function(){
console.log('App listening on port 8080');
});
*/