Skip to content
This repository has been archived by the owner on Nov 11, 2018. It is now read-only.

Feature/v17 support #141

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js

node_js:
- "4"
- "node"

sudo: false
106 changes: 50 additions & 56 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,52 @@ const Ws = require('ws');

// Declare internals

const internals = {};


internals.defaults = {
endpoint: '/debug/console',
queryKey: 'debug',
template: 'index',
host: undefined,
address: undefined,
authenticateEndpoint: false,
port: 0
const internals = {
defaults : {
endpoint: '/debug/console',
queryKey: 'debug',
template: 'index',
host: undefined,
address: undefined,
authenticateEndpoint: false,
port: 0
}
};

exports.plugin = {
pkg: require('../package.json'),
once: true,
register: async function(server, options) {

exports.register = function (server, options, next) {

const settings = Hoek.applyToDefaults(internals.defaults, options);
const settings = Hoek.applyToDefaults(internals.defaults, options);

server.views({
engines: { html: { module: Handlebars } },
path: Path.join(__dirname, '../templates')
});
server.views({
engines: { html: { module: Handlebars } },
relativeTo: __dirname,
path: '../templates'
});

server.route({
method: 'GET',
path: settings.endpoint + '/{file*2}',
config: {
auth: settings.authenticateEndpoint,
handler: {
directory: {
path: Path.join(__dirname, '../public'),
listing: false,
index: false
server.route({
method: 'GET',
path: settings.endpoint + '/{file*2}',
config: {
auth: settings.authenticateEndpoint,
handler: {
directory: {
path: Path.join(__dirname, '../public'),
listing: false,
index: false
}
},
plugins: {
lout: false
}
},
plugins: {
lout: false
}
}
});

const subscribers = {}; // Map: debug session -> [ subscriber ]
const tv = new Hapi.Server();
tv.connection({ host: settings.host, address: settings.address, port: settings.port });
});

tv.start(() => {
const subscribers = {}; // Map: debug session -> [ subscriber ]
const tv = Hapi.Server({ host: settings.host, address: settings.address, port: settings.port });
await tv.initialize();

const ws = new Ws.Server({ server: tv.listener });
ws.on('connection', (socket) => {
Expand Down Expand Up @@ -113,8 +113,7 @@ exports.register = function (server, options, next) {
}
});

server.ext('onRequest', (request, reply) => {

server.ext('onRequest', (request, h) => {
if (request.plugins.tv && request.plugins.tv.debugId) {

const key = settings.queryKey;
Expand All @@ -126,7 +125,7 @@ exports.register = function (server, options, next) {
request.setUrl(Url.format(request.url));
}

return reply.continue();
return h.continue;
});

const onLog = function (request, event, tags) {
Expand Down Expand Up @@ -161,37 +160,32 @@ exports.register = function (server, options, next) {
transmit('*');
};

server.on('request', onLog );
server.on('request-internal', (request, event, tags) => {

server.events.on({ name: 'request', channels: 'app' }, onLog );
server.events.on({ name: 'request', channels: 'error' }, onLog );
server.events.on({ name: 'request', channels: 'internal' }, (request, event, tags) => {
const key = settings.queryKey;
if (tags.received && request.query[key] && !request.plugins.tv) { // first internal event has tag received: true
request.plugins.tv = { debugId: request.query[key] };
}

onLog(request, event, tags);
});
server.on('response', (request) => {
server.events.on('response', (request) => {

const event = {
timestamp: Date.now(),
request: request.id,
server: request.connection.info.uri,
request: request.info.id,
server: request.server.info.uri,
response: true,
data: {
url: request.url.path,
method: request.method,
statusCode: request.response.statusCode,
payload: request.response.variety === 'plain' ? request.response.source : null
}
};

onLog(request, event);
});

return next();
});
};


exports.register.attributes = {
pkg: require('../package.json')
};
}
};
Loading