-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (56 loc) · 1.71 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
var express=require('express');
var app = express();
var server = require('http').Server(app);
require('./controller/service/socketService')(app,server);
var path = require('path');
var ejs = require('ejs');
var router = require('./routers/loginRouter');
//var errorhandler = require('errorhandler');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var setting = require('./controller/models/setting');
var favicon = require('static-favicon');
var logger = require('morgan');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
/*app.use(session({
secret: setting.cookieSecret,
store: new MongoStore({
db : setting.db
})
}));*/
app.set('port', process.env.PORT || 80);
app.set('views', path.join(__dirname, 'views'));
app.engine('.html', ejs.__express);
app.set('view engine', 'html');// app.set('view engine', 'ejs');
app.use(cookieParser());
app.use(favicon());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(session({
secret:setting.cookieSecret,
key:setting.db,
cookie:{maxAge:1000*60*60*24*30},
store:new MongoStore({db:setting.db})
}));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', router);
//获取在线人数
router.get('/onlines.do', function (req, res) {
var result=app.locals.onlines.map(function(item){
if(req.session.user.openId!==item.openId){
return item;
}
});
res.json(result);
});
// development only
if (process.env.NODE_ENV === 'development') {
console.log("development");
app.use(logger('dev'));
//app.use(errorhandler())
}
server.listen(app.get('port'),function(){
console.log("server was started!");
app.locals.onlines=[];
});