-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (46 loc) · 1.73 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
require('dotenv').config();
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');
const LocalStrategy = require('passport-local');
const methodOverride = require('method-override');
const User = require('./models/user');
// requiring routes
const indexRoute = require('./routes/index');
const movieRoute = require('./routes/movie');
const celebrityRoute = require('./routes/celebrity');
const url = process.env.DATABASEURL || 'mongodb://localhost/moviedazz';
mongoose.set('useUnifiedTopology', true);
mongoose.set('useCreateIndex', true);
mongoose.connect(url, { useNewUrlParser: true, useFindAndModify: false });
const db = mongoose.connection;
db.on('error', (error) => console.log(error));
db.once('open', () => console.log('Connected to Mongoose'));
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride('_method'));
/* PASSPORT CONFIGURATION */
app.use(require('express-session')({
secret: 'Once again rusty wins cutest dog!',
resave: false,
saveUninitialized: false,
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use((req, res, next) => {
res.locals.currentUser = req.user;
next();
});
app.use('/movie', movieRoute);
app.use('/celebrity', celebrityRoute);
app.use('/', indexRoute);
app.listen(process.env.PORT || 5001, () => {
console.log('MovieDazZ Has Started');
console.log(`Server is listening at localhost:${process.env.PORT || 5001}`);
});