Skip to content

Commit

Permalink
switched for rendering to express framework
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubOboza committed May 10, 2012
1 parent 4d89110 commit f0777d9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"test": "mocha -R landing spec/*.spec.js"
},
"dependencies": {
"socket.io": ">= 0.0.0"
"socket.io": ">= 0.0.0",
"express": "2.5.8",
"ejs": ">= 0.7.1"
},
"devDependencies": {},
"optionalDependencies": {},
Expand Down
1 change: 1 addition & 0 deletions views/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: finish me
16 changes: 16 additions & 0 deletions views/layout.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('entry', function (data) {
console.log(data);
});
</script>
</head>

<body>
<%- body %>
</body>

</html>
34 changes: 20 additions & 14 deletions web.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
var app = require('http').createServer(handler)
var express = require('express')
, app = express.createServer()
, io = require('socket.io').listen(app)
, fs = require('fs');

var stalker = require("./lib/stalker");

var port = process.env['PORT'] || 4444 ;

app.listen(port);
app.configure('development', function(){
app.use(express.static(__dirname + '/public'));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.set('view engine', 'ejs');
});

function handler (req, res) {
fs.readFile(__dirname + '/public/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
app.configure('production', function(){
app.use(express.static(__dirname + '/public'));
app.use(express.errorHandler());
app.set('view engine', 'ejs');
});

res.writeHead(200);
res.end(data);
});
}
app.listen(port);

app.get('/', function (req, res) {
res.render('index.ejs');
});

io.sockets.on('connection', function (socket) {
new stalker("test.file", function(content){
socket.emit('entry', { content: content });
});
});
});


0 comments on commit f0777d9

Please sign in to comment.