JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
move output to browser (from inspector)
authorJason Woofenden <jason@jasonwoof.com>
Wed, 30 Jan 2013 08:05:31 +0000 (03:05 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Wed, 30 Jan 2013 08:05:31 +0000 (03:05 -0500)
index.html
publish-my-session.coffee

index daa26ae..d540026 100644 (file)
@@ -1,7 +1,38 @@
-<script src="/socket.io/socket.io.js"></script>
-<script>
-  var socket = io.connect('http://localhost');
-  socket.on('write', function (data) {
-    console.log(data);
-  });
-</script>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+       <title>Remote Terminal Viewer</title>
+       <script src="/jquery.js"></script>
+       <script src="/socket.io/socket.io.js"></script>
+       <script>
+               $(function() {
+                       var $body = $('body');
+                       var lines = 0;
+                       var log = function (str) {
+                               if(lines > 66) {
+                                       $($body.children().get(0)).remove();
+                               } else {
+                                       lines += 1;
+                               }
+                               $body.append($('<div>').text(str));
+                       };
+                       var socket = io.connect('http://localhost');
+                       socket.on('write', function (data) {
+                               log(data);
+                       });
+               });
+       </script>
+       <style>
+               body {
+                       color: white;
+                       background: black;
+                       font-family: monospace;
+                       font-size: 12px;
+                       line-height: 14px;
+                       white-space: pre;
+               }
+       </style>
+</head>
+<body>
+</body>
+</html>
index bd2cd30..fec3467 100644 (file)
@@ -1,10 +1,20 @@
 handler = (req, res) ->
-       fs.readFile __dirname + '/index.html', (err, data) ->
-               if err
-                       res.writeHead(500)
-                       return res.end('Error loading index.html')
+       err = (req, res) ->
+               res.writeHead(404, 'Content-Type': 'text/plain')
+               return res.end("Error loading #{req.url}")
+       switch req.url
+               when '/', '/index.html'
+                       filename = __dirname + '/index.html'
+                       type = 'text/html'
+               when '/jquery.js'
+                       filename = '/usr/share/javascript/jquery/jquery.min.js'
+                       type = 'text/javascript'
+               else
+                       return err req, res
+       fs.readFile filename, (err, data) ->
+               return err req, res if err
 
-               res.writeHead(200)
+               res.writeHead(200, 'Content-Type': type)
                res.end(data)
 
 app = require('http').createServer(handler)