Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated demo to automatically serve all files in the web directory in…

…stead of listing out individual files.
  • Loading branch information...
commit 50c1bcb766a67ce01c4c9c1733de33543e79c0c0 1 parent 4efd00b
@scottgonzalez authored
Showing with 17 additions and 18 deletions.
  1. +17 −18 demo/chat.js
View
35 demo/chat.js
@@ -1,11 +1,13 @@
var sys = require("sys"),
+ fs = require("fs"),
chat = require('../lib/server'),
router = require("../lib/router");
-// create chat server and a single channel
+// 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) {
@@ -16,21 +18,18 @@ chatServer.addChannel({
sys.puts(msg.nick + " part");
});
-// chat app
-chatServer.passThru("/", router.staticHandler("web/index.html"));
-
-// CSS
-chatServer.passThru("/css/layout.css", router.staticHandler("web/css/layout.css"));
-chatServer.passThru("/css/reset.css", router.staticHandler("web/css/reset.css"));
-
-// Images
-["background.png", "button.png", "footer.png", "glows.png", "header-bg.png",
- "inset-border-l.png", "inset-border.png", "metal.jpg", "node-chat.png",
- "send.png"].forEach(function(file) {
- chatServer.passThru("/images/" + file, router.staticHandler("web/images/" + file));
+// 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));
+ }
});
-
-// JS
-chatServer.passThru("/js/jquery-1.4.2.js", router.staticHandler("web/js/jquery-1.4.2.js"));
-chatServer.passThru("/js/nodechat.js", router.staticHandler("web/js/nodechat.js"));
-chatServer.passThru("/js/client.js", router.staticHandler("web/js/client.js"));
+}
+serveFiles(__dirname + "/web", "");
+chatServer.passThru("/", router.staticHandler(__dirname + "/web/index.html"));
Please sign in to comment.
Something went wrong with that request. Please try again.