mirror of https://github.com/mthenw/frontail.git
Init source
commit
77bcdc67e8
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env node
|
||||
require('./../lib/frontail');
|
|
@ -0,0 +1,66 @@
|
|||
var program = require('commander')
|
||||
, http = require('http')
|
||||
, fs = require('fs')
|
||||
, socketio = require('socket.io')
|
||||
, spawn = require('child_process').spawn;
|
||||
|
||||
/**
|
||||
* Parse arg
|
||||
*/
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.usage('[options] [file ...]')
|
||||
.option('-p, --port <port>', 'server port, default 9001', Number, 9001)
|
||||
.option('-n, --number <number>', 'starting lines number, default 10', Number, 10)
|
||||
.parse(process.argv);
|
||||
|
||||
if (program.args.length === 0) {
|
||||
process.exit();
|
||||
} else {
|
||||
var files = program.args.join(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Server setup
|
||||
*/
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
fs.readFile(__dirname + '/index.html', function (err, data) {
|
||||
if (err) {
|
||||
res.writeHead(500, {'Content-Type': 'text/plain'});
|
||||
res.end('Interal error');
|
||||
} else {
|
||||
res.writeHead(200, {'Content-Type': 'text/html'});
|
||||
res.end(data.toString('utf-8').replace(/__TITLE__/g, 'tail -F ' + files), 'utf-8');
|
||||
}
|
||||
});
|
||||
});
|
||||
server.listen(program.port);
|
||||
|
||||
/**
|
||||
* socket.io setup
|
||||
*/
|
||||
|
||||
var io = socketio.listen(server);
|
||||
io.set("log level", 2);
|
||||
|
||||
/**
|
||||
* Connect to socket and send starting data
|
||||
*/
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
var tail = spawn('tail', ['-n', program.number, files]);
|
||||
tail.stdout.on('data', function (data) {
|
||||
socket.emit('lines', data.toString('utf-8').split('\n'));
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Send incoming data
|
||||
*/
|
||||
|
||||
var tail = spawn('tail', ['-F', files]);
|
||||
tail.stdout.on('data', function (data) {
|
||||
io.sockets.emit('lines', data.toString('utf-8').split('\n'));
|
||||
});
|
|
@ -0,0 +1,79 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>__TITLE__</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style type="text/css">
|
||||
/* Styles mainly from http://twitter.github.com/bootstrap/ */
|
||||
* {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
font-size: 13px;
|
||||
line-height: 18px;
|
||||
color: #333;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
background-color: #2C2C2C;
|
||||
background-image: -webkit-linear-gradient(top, #333, #222);
|
||||
background-repeat: repeat-x;
|
||||
box-shadow: rgba(0, 0, 0, 0.246094) 0px 1px 3px 0px, rgba(0, 0, 0, 0.0976563) 0px -1px 0px 0px inset;
|
||||
position: fixed;
|
||||
left: 0px;
|
||||
right: 0px;
|
||||
top: 0px;
|
||||
color: #fff;
|
||||
display: block;
|
||||
height: 24px;
|
||||
font-size: 20px;
|
||||
font-weight: 200;
|
||||
padding: 8px 50px;
|
||||
}
|
||||
|
||||
.log {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.log .line {
|
||||
padding: 0 50px;
|
||||
margin-left: 10em;
|
||||
text-indent: -10em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar">__TITLE__</div>
|
||||
<pre class="log"></pre>
|
||||
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var logContainer = document.getElementsByClassName('log')[0];
|
||||
|
||||
var log = function(line) {
|
||||
var p = document.createElement('p');
|
||||
p.className = 'line';
|
||||
p.innerHTML = line;
|
||||
|
||||
logContainer.appendChild(p);
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
};
|
||||
|
||||
var socket = new io.connect();
|
||||
socket.on('connect', function() {
|
||||
log('<i>Connected...</i>');
|
||||
});
|
||||
socket.on('lines', function(lines) {
|
||||
for (var i in lines) {
|
||||
log(lines[i]);
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue