-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
64 lines (52 loc) · 1.75 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 http = require('http');
// 服务器相关
var express = require('express');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({
extended: false,
limit: '5mb'
})
var MemoryStore = require('express-session/session/memory');
var session_store = new MemoryStore();
// 程序主体用到的第三方模块
// var nodeJSX = require('node-jsx').install({harmony: true});
var react = require('react');
// 我的模块
// var d = require('./assets/lib/components/ChatApp.react.js');
// server初始化, set配置, 中间件
var app = express();
var server = http.Server(app);
app.set('view engine', 'jade');
// app.use(morgan('dev'));
app.use( express.static(__dirname + "/assets") );
app.use(cookieParser());
app.use(session({
secret: 'cookieSecret',
key: 'LX',//cookie name
resave: true,
saveUninitialized: true,
cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
store: session_store,
}));
require('./backend/db.js');
var msg = require('./backend/msg.js');
var thread = require('./backend/thread.js');
var user = require('./backend/user.js');
var userSecret = require('./backend/userSecret.js');
//duanxin jiekou
var emitMessage = require('./backend/dayuSDKsign/emitMessage')
// 路由
var route = require('./backend/routes/route');
route(app,msg,thread,user,userSecret,urlencodedParser,emitMessage);
var port = 3003;
// must be server ! can not be app.listen
// or socket.io can't start...
server.listen(port, function(){
console.log('server is listening at:', port );
});
var socketChat = require('./backend/socketChat');
socketChat(server,msg,thread,user,userSecret,session_store);