-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (52 loc) · 1.61 KB
/
app.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
let express = require('express')
let nodemailer = require('nodemailer')
let mongoose = require('mongoose')
mongoose.connect('mongodb+srv://egbe:[email protected]/blogs?retryWrites=true&w=majority', { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true }).then(() => console.log('MongoDB connected...'))
.catch(err => console.log('There was a ' + err));
let app = express()
let blogController = require('./controllers/blogControllers')
app.set('view engine', 'ejs')
app.use('/assets', express.static('./public/assets'))
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
auth: {
user: '[email protected]',
pass: '123Baba..',
},
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
},
});
blogController(app, mongoose)
app.post('/sendMail', (req, res) => {
const mailData = {
from: '[email protected]', // sender address
to: '[email protected]', // list of receivers
subject: 'Test',
text: req.body.name + ': \n' + req.body.text
};
transporter.sendMail(mailData, function (error, info) {
if (error) {
console.log(error)
} else {
console.log(info)
}
})
})
app.get('/contact', (req, res) => {
res.render('contact')
})
app.get('/', (req, res) => {
res.render('index')
})
app.get('/admin', (req, res) => {
res.render('admin')
})
app.get('/about', (req, res) => {
res.render('about')
})
app.get('/portfolio', (req, res) => {
res.render('portfolio')
})
app.listen(process.env.PORT || 3000)