Permalink
Browse files

using "send" module to serve static files

  • Loading branch information...
1 parent fdd69f6 commit 52836fc8d827623fdb5f4c123659e6681c67306c @bobrik committed Aug 14, 2012
Showing with 18 additions and 4 deletions.
  1. +16 −3 lib/PuperGrep.js
  2. +2 −1 package.json
View
@@ -1,5 +1,9 @@
(function(module) {
var LogReaderManager = require("./LogReaderManager"),
+ http = require("http"),
+ send = require("send"),
+ url = require("url"),
+ path = require("path")
socketIO = require("socket.io");
function PuperGrep() {
@@ -14,7 +18,14 @@
var self = this,
manager = self.getLogReaderManager();
- self.io = socketIO.listen(port, host);
+ self.http = http.createServer(function(req, res) {
+ var file = url.parse(req.url).pathname,
+ root = path.join(__dirname, "..", "public");
+
+ send(req, file).root(root).pipe(res);
+ });
+
+ self.io = socketIO.listen(self.http);
self.io.sockets.on("connection", function(socket) {
var lastLog = {
@@ -86,11 +97,13 @@
});
});
});
+
+ self.http.listen(port, host);
};
PuperGrep.prototype.close = function() {
- if (!this.io) {
- this.io.server.close();
+ if (this.http) {
+ this.http.close();
}
};
View
@@ -4,7 +4,8 @@
"description": "Real-time grep for your logs right in your favorite modern browser made with Twitter Bootstrap.",
"main": "index.js",
"dependencies": {
- "socket.io": ">=0.9.6"
+ "socket.io": ">=0.9.6",
+ "send": ">=0.0.3"
},
"devDependencies": {},
"repository": {

0 comments on commit 52836fc

Please sign in to comment.