-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (40 loc) · 1.33 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
/**
* Created by haojin on 2016/3/20 0020.
*/
var express = require('express');
var port = process.env.PORT || 8989;
var app = express();
var path = require('path');
var http = require('http').Server(app);
var io = require('socket.io')(http);
//var routes = require('./routes/index');
var bodyParser = require('body-parser');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var flash = require('connect-flash');
var config = require('./config');
var webRouter = require('./web-router');
app.use(session({
secret: config.cookieSecret,
key: config.key,//cookie name
cookie:{maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
store: new MongoStore({
url: 'mongodb://localhost/forum'
}),
resave:true,
saveUninitialized: true
}));
app.set('views','./views');
app.set('view engine', 'html');
app.engine('html', require('ejs-mate'));
//app.set('view engine','ejs');
app.use(flash());
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: false }));
app.use(express.static(path.join(__dirname, 'bower_components')));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', webRouter);
var socket_event = require('./socket-event');
io.on('connection', socket_event);
http.listen(port);
console.log('forum started at port:'+port);