-
Notifications
You must be signed in to change notification settings - Fork 66
/
chat.js
35 lines (31 loc) · 978 Bytes
/
chat.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
var sys = require("sys"),
fs = require("fs"),
chat = require('../lib/server'),
router = require("../lib/router");
// create chat server
var chatServer = chat.createServer();
chatServer.listen(8001);
// create a channel and log all activity to stdout
chatServer.addChannel({
basePath: "/chat"
}).addListener("msg", function(msg) {
sys.puts("<" + msg.nick + "> " + msg.text);
}).addListener("join", function(msg) {
sys.puts(msg.nick + " join");
}).addListener("part", function(msg) {
sys.puts(msg.nick + " part");
});
// server static web files
function serveFiles(localDir, webDir) {
fs.readdirSync(localDir).forEach(function(file) {
var local = localDir + "/" + file,
web = webDir + "/" + file;
if (fs.statSync(local).isDirectory()) {
serveFiles(local, web);
} else {
chatServer.passThru(web, router.staticHandler(local));
}
});
}
serveFiles(__dirname + "/web", "");
chatServer.passThru("/", router.staticHandler(__dirname + "/web/index.html"));