-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (40 loc) · 1.34 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
/* Copyright 2012-2016 QiuYuhui
written by : qiu
written for : http://inir.cn/realtime-multiplayer/
MIT Licensed.
Usage : node app.js
*/
var http = require('http'),
socket = require('socket.io'),
express = require('express'),
UUID = require('node-uuid'),
app = express(),
server = http.createServer(app),
port = process.env.PORT || 4004,
verbose = true; //false;
//服务端监听端口
server.listen(port);
//答应监听信息
console.log('Listening on port %d', port);
//指定/路径到index.html文件
app.get('/', function (req, res) {
console.log('trying to load %s', __dirname + '/index.html');
res.sendfile('/index.html', {root: __dirname});
});
//指定/*路径,*代表相应的文件输出显示
app.get('/*', function (req, res, next) {
var file = req.params[0];
if (verbose) console.log('\t :: Express :: file requested : ' + file);
res.sendfile(__dirname + '/' + file);
}); //app.get *
/* Socket.IO server set up. */
//创建一个 socket.io 实例使用 express server
var io = socket.listen(server);
//socket.io 配置
//See http://socket.io/
io.configure(function () {
io.set('log level', 0);
io.set('authorization', function (handshakeData, callback) {
callback(null, true); // error first callback style
});
});