Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* marking logs
* pausing logs
* number of unread logs in favicon
* themes (default, dark)
* Dark mode
* [highlighting](#highlighting)
* search (`Tab` to focus, `Esc` to clear)
* set filter from url parameter `filter`
Expand All @@ -43,7 +43,6 @@
-p, --port <port> listening port, default 9001
-n, --number <number> starting lines number, default 10
-l, --lines <lines> number on lines stored in browser, default 2000
-t, --theme <theme> name of the theme (default, dark)
-d, --daemonize run as daemon
-U, --user <username> Basic Authentication username, option works only along with -P option
-P, --password <password> Basic Authentication password, option works only along with -U option
Expand Down
46 changes: 23 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const cookie = require('cookie');
const cookieParser = require('cookie-parser');
const crypto = require('crypto');
const path = require('path');
const SocketIO = require('socket.io');
const { Server } = require('socket.io');
const fs = require('fs');
const untildify = require('untildify');
const tail = require('./lib/tail');
Expand All @@ -22,26 +22,27 @@ if (program.args.length === 0) {
console.error('Arguments needed, use --help');
process.exit();
}
const options = program.opts();

/**
* Init usage statistics
*/
const stats = usageStats(!program.disableUsageStats, program);
const stats = usageStats(!options.disableUsageStats, options);
stats.track('runtime', 'init');
stats.time('runtime', 'runtime');

/**
* Validate params
*/
const doAuthorization = !!(program.user && program.password);
const doSecure = !!(program.key && program.certificate);
const doAuthorization = !!(options.user && options.password);
const doSecure = !!(options.key && options.certificate);
const sessionSecret = String(+new Date()) + Math.random();
const files = program.args.join(' ');
const filesNamespace = crypto.createHash('md5').update(files).digest('hex');
const urlPath = program.urlPath.replace(/\/$/, ''); // remove trailing slash
const urlPath = options.urlPath.replace(/\/$/, ''); // remove trailing slash

if (program.daemonize) {
daemonize(__filename, program, {
if (options.daemonize) {
daemonize(__filename, options, {
doAuthorization,
doSecure,
});
Expand All @@ -52,31 +53,30 @@ if (program.daemonize) {
const appBuilder = connectBuilder(urlPath);
if (doAuthorization) {
appBuilder.session(sessionSecret);
appBuilder.authorize(program.user, program.password);
appBuilder.authorize(options.user, options.password);
}
appBuilder
.static(path.join(__dirname, 'web', 'assets'))
.index(
path.join(__dirname, 'web', 'index.html'),
files,
filesNamespace,
program.theme
filesNamespace
);

const builder = serverBuilder();
if (doSecure) {
builder.secure(program.key, program.certificate);
builder.secure(options.key, options.certificate);
}
const server = builder
.use(appBuilder.build())
.port(program.port)
.host(program.host)
.port(options.port)
.host(options.host)
.build();

/**
* socket.io setup
*/
const io = new SocketIO({ path: `${urlPath}/socket.io` });
const io = new Server({ path: `${urlPath}/socket.io` });
io.attach(server);

if (doAuthorization) {
Expand Down Expand Up @@ -106,13 +106,13 @@ if (program.daemonize) {
* Setup UI highlights
*/
let highlightConfig;
if (program.uiHighlight) {
if (options.uiHighlight) {
let presetPath;

if (!program.uiHighlightPreset) {
if (!options.uiHighlightPreset) {
presetPath = path.join(__dirname, 'preset', 'default.json');
} else {
presetPath = path.resolve(untildify(program.uiHighlightPreset));
presetPath = path.resolve(untildify(options.uiHighlightPreset));
}

if (fs.existsSync(presetPath)) {
Expand All @@ -126,21 +126,21 @@ if (program.daemonize) {
* When connected send starting data
*/
const tailer = tail(program.args, {
buffer: program.number,
buffer: options.number,
});

const filesSocket = io.of(`/${filesNamespace}`).on('connection', (socket) => {
socket.emit('options:lines', program.lines);
socket.emit('options:lines', options.lines);

if (program.uiHideTopbar) {
if (options.uiHideTopbar) {
socket.emit('options:hide-topbar');
}

if (!program.uiIndent) {
if (!options.uiIndent) {
socket.emit('options:no-indent');
}

if (program.uiHighlight) {
if (options.uiHighlight) {
socket.emit('options:highlightConfig', highlightConfig);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/daemonize.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const daemon = require('daemon-fix41');
const daemon = require('daemonize-process');
const fs = require('fs');

const defaultOptions = {
Expand Down
6 changes: 0 additions & 6 deletions lib/options_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ program
Number,
2000
)
.option(
'-t, --theme <theme>',
'name of the theme (default, dark)',
String,
'default'
)
.option('-d, --daemonize', 'run as daemon')
.option(
'-U, --user <username>',
Expand Down
2 changes: 1 addition & 1 deletion lib/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const ua = require('universal-analytics');
const isDocker = require('is-docker');
const Configstore = require('configstore');
const uuidv4 = require('uuid/v4');
const { v4: uuidv4 } = require('uuid');
const pkg = require('../package.json');

const trackingID = 'UA-129582046-1';
Expand Down
Loading