-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
119 lines (85 loc) · 2.77 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var express = require("express"),
mongoose = require("mongoose"),
bodyParser = require("body-parser"),
passport = require("passport"),
passportLocal = require("passport-local"),
flash = require("connect-flash"),
seedDB = require("./seed"),
allHymns = require("./models/combinedhymn"),
TheChurchHymnal = require("./models/hymns"),
ChildrenSupplement = require("./models/childsup"),
User = require("./models/user"),
methodOverRide = require("method-override"),
keys = require("./config/keys"),
allHymnsRoutes = require("./routes/all_hymns"),
churchHymnalRoutes = require("./routes/church_hymnal"),
authenticationRoutes = require("./routes/authentication"),
app = express();
seedDB();
// setting the environment port and port location.
app.set ("port", (process.env.PORT || 3000));
app.use(express.static(__dirname + "/public"));
app.use(bodyParser.urlencoded({extended: true}));
app.use(flash());
app.use(methodOverRide("_method"));
app.set("view engine", "ejs");
app.use(churchHymnalRoutes);
app.use(allHymnsRoutes);
app.use(authenticationRoutes);
console.log(process.env.DATABASEURL);
//Mongo Global Promise
mongoose.Promise = require("bluebird");
mongoose.Promise = global.Promise;
// Connection of DB
mongoose.connect(keys.mongoURI, {})
.then(function(){
console.log("MongoDB Connected");
})
.catch(err => console.log(err));
//Passport Configuration
app.use(require("express-session")({
secret: "secret",
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new passportLocal(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
//Middlewear for login logic
app.use(function(req, res, next){
res.locals.currentUser = req.user;
res.locals.error = req.flash("error");
res.locals.success = req.flash("success");
next();
})
// Index Route for Home page.
app.get("/", function(req,res){
res.render("homepage", {currentUser: req.user});
})
//Contact Us ROute
app.get("/contact", function(req, res){
res.render('contact', {currentUser: req.user });
})
//Server listening for request to start server.
app.listen(app.get ("port"), function(){
console.log("Hymn Server has Started.")
});
//Other Hymns Routes
//Index Route for Baptist hymnal page
app.get("/baptist_hymnal", function(req,res){
res.render("baptist_hymnal");
})
//Index Route for CAC Hymnal page
app.get("/cac_hymnal",function(req,res){
res.render("cac_hymnal");
})
//Index Route for The hymnal Book
app.get("/the_hymnbook", function(req,res){
res.render("the_hymnbook");
})
//Index Route for Chant book
app.get("/chant_book", function(req,res){
res.render("chant_book");
})