-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
64 lines (49 loc) · 1.7 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
56
57
58
59
60
61
62
63
64
var express = require('express');
var app = express();
var port = process.env.PORT || 8080;
var cookieParser = require('cookie-parser');
var session = require('express-session');
var morgan = require('morgan');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var passport = require('passport');
var flash = require('connect-flash');
var MongoStore = require('connect-mongo')(session);
var configDB = require('./config/database.js');
mongoose.connect(configDB.url);
require('./config/passport')(passport);
app.use(morgan('dev'));
app.use(cookieParser());
app.use(bodyParser.urlencoded({extended: false}));
app.use(session({secret: 'anystringoftext',
saveUninitialized: true,
resave: true,
store: new MongoStore({ mongooseConnection: mongoose.connection,
ttl: 2 * 24 * 60 * 60 })}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
app.use(function(req, res, next){
console.log(req.session);
console.log("===================");
console.log(req.user);
next();
});
app.set('view engine', 'ejs');
var api = express.Router();
require('./app/routes/api.js')(api, passport);
app.use('/api', api);
var auth = express.Router();
require('./app/routes/auth.js')(auth, passport);
app.use('/auth', auth);
var secure = express.Router();
require('./app/routes/secure.js')(secure, passport);
app.use('/', secure);
// app.use('/', function(req, res){
// res.send('Our First Express program!');
// console.log(req.cookies);
// console.log('================');
// console.log(req.session);
// });
app.listen(port);
console.log('Server running on port: ' + port);