-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
70 lines (56 loc) · 1.67 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
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var passport = require('passport');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var LocalStrategy = require('passport-local').Strategy;
var app = express();
//Make new databse
mongoose.connect("mongodb://MINET:[email protected]:31583/minetx");
var db = mongoose.connection;
//If Mongo Error
db.on('error', console.error.bind(console, 'connection error'));
//Setting up sessions+cookies
app.use(session({
secret: 'JagdishKumar',
resave: false,
saveUninitialized: false,
store: new MongoStore({
mongooseConnection: db
})
}));
app.use(passport.initialize());
app.use(passport.session());
var User = require('./models/user');
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();
});
//Setting up body-parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
//Setting public directory
app.use(express.static(__dirname + '/public'));
//Setting view engine
app.set('view engine', 'pug');
app.set('views', __dirname + '/views');
//Setting routes
var home = require('./routes/index');
app.use('/', home);
var dashboard = require('./routes/dashboard');
app.use('/dashboard', dashboard);
//404
app.use((res, req, next) => {
next(err);
});
//Error Handler
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.render('error');
});
//Listening
app.listen(process.env.PORT || 5000);