-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
50 lines (45 loc) · 1.27 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
/**
* Created by wz on 17-3-1.
*/
var express = require('express'),
path = require('path'),
mongoose = require('mongoose'),
dbConnector = require('./dbConnector'),
passport = require('passport'),
session = require('express-session'),
dbCached = require('connect-mongo')(session),
bodyParser = require('body-parser'),
setupPassport = require('./setupPassport'),
router = require('./router.js');
var app = express();
dbConnector();
app.set('views', path.join(__dirname, "views"));
app.set('view engine', 'ejs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(session({
secret: 'kitten',
resave: true,
saveUninitialized: true,
store: new dbCached({
mongooseConnection: mongoose.connection
})
}));
app.use(passport.initialize());
app.use(passport.session());
setupPassport();
app.use(function (req, res, next) {
res.success = function (status) {
if (!status)status = 'success';
res.send({statuscode: 0, status: status});
};
res.failed = function (status) {
if (!status)status = 'failed';
res.send({statuscode: -1, status: status});
};
next();
});
app.use(router);
app.listen(3001, function () {
console.log('start listening at 3001');
});