-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
55 lines (46 loc) · 1.32 KB
/
server.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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const flash = require('connect-flash');
const mongoose = require('mongoose');
const session = require('express-session');
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const db = require('./models');
const User = db.User;
const Cage = db.Cage;
//Middleware
app.use(cookieParser());
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false
})
);
app.use(passport.initialize());
app.use(passport.session());
// passport config
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
//flash messages
app.use(flash());
app.use(function(req, res, next) {
res.locals.messages = require('express-messages')(req, res);
next();
});
app.use(express.static('./public'));
app.use(bodyParser());
//Require all resources in app
app.use(require('./routes'));
app.set('view engine', 'ejs');
// use res.render to load up an ejs view file
app.locals.user = false;
//Create server
var port = process.env.PORT || 8000;
app.listen(port, function() {
console.log('running on port', port);
});
module.exports = app;