-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·79 lines (66 loc) · 2.11 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const express = require('express'),
path = require('path'),
bodyParser = require('body-parser'),
cors = require('cors'),
passport = require('passport'),
mongoose = require('mongoose'),
config = require('./config/database'),
nodemailer = require('nodemailer');
// var transporter = nodemailer.createTransport({
// service: 'gmail',
// auth: {
// user: '[email protected]',
// pass: 'lephan1994'
// }
// });
// var mailOptions = {
// from: '[email protected]',
// to: '[email protected] ',
// subject: 'Pontes Network Test sending Email using Node.js',
// html: {path: './views/mailer.html'}
// }
// transporter.sendMail(mailOptions, function(error, info){
// if (error) {
// console.log(error);
// } else {
// console.log('Email sent: ' + info.response);
// }
// });
var app = express();
var PORT = process.env.PORT || 8080;
var indexRoutes = require("./routes/indexRoutes");
var contactMessage = require("./routes/contact_message");
var letter = require("./routes/letter");
var user = require("./routes/user");
var letterComment = require("./routes/letter_comment");
// Connect To Database
mongoose.connect(config.database);
// On Connection
mongoose.connection.on('connected', () => {
console.log('Connected to database '+config.database);
});
// On Error
mongoose.connection.on('error', (err) => {
console.log('Database error: '+err);
});
//CORS middleware
app.use(cors());
//body-parser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
//Set Static Folder
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static('images'));
app.use(indexRoutes);
app.use(contactMessage);
app.use(letter);
app.use(user);
app.use(letterComment);
//When the users request to any route, we will pass the controler to our Agular app
app.use('*', function (req, res) {
res.sendFile(path.join(__dirname, 'public/index.html'));
})
//Start server
app.listen(PORT, function(){
console.log("Sever has started at port "+PORT);
})