Skip to content

Commit

Permalink
Breaking changes: modified to work with Hapi v17
Browse files Browse the repository at this point in the history
One of the most breaking changes is that Hapi v17 does not support multiple connections, so now they are replaced with one.
Labels are removed in Hapi v17, so everything related to labels in this plugin is removed too.
Listening to server events is now on server.events.on, instead of server.on
  • Loading branch information
Y-LyN-10 committed Nov 10, 2017
1 parent 91db5cc commit 0143f72
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions lib/index.js
@@ -1,9 +1,10 @@
// Load modules
var Chalk = require('chalk');
var Hoek = require('hoek');
var Joi = require('joi');
var Pkg = require('../package.json');
'use strict';

// Load modules
const Chalk = require('chalk');
const Hoek = require('hoek');
const Joi = require('joi');
const Pkg = require('../package.json');

// Declare internals
var internals = {
Expand All @@ -13,41 +14,32 @@ var internals = {
}
};


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

var result = Joi.validate(options, internals.schema);
Hoek.assert(!result.error, result.error && result.error.annotate());
options = result.value;

server.expose('text', function () {

var info = this.info();
return internals.printableInfo(info, options);
});

server.expose('info', function () {

return internals.getRouteInfo(server, options);
});

if (options.showStart) {
server.on('start', function () {

server.events.on('start', function () {
var out = server.plugins[Pkg.name].text();
console.log(out);
});
}

return next();
};


exports.register.attributes = {
pkg: Pkg
};


internals.printableInfo = function (connections, options) {

var out = '';
Expand Down Expand Up @@ -91,12 +83,8 @@ internals.printableRoutes = function (routes, options) {


internals.printableTitle = function (connection) {

var title = Chalk.underline(connection.uri);
if (connection.labels.length) {
var labels = '[' + Chalk.magenta(connection.labels.join(', ')) + ']';
title += ' ' + labels;
}
return Chalk.cyan(title);
};

Expand All @@ -107,17 +95,13 @@ internals.getRouteInfo = function (server, options) {

var routingTable = server.table();

routingTable.forEach(function (connection) {
var connectionInfo = {
uri: server.info.uri,
routes: []
};

var connectionInfo = {
uri: connection.info.uri,
labels: connection.labels,
routes: []
};

internals.connectionInfo(connection.table, options, connectionInfo);
connections.push(connectionInfo);
});
internals.connectionInfo(routingTable, options, connectionInfo);
connections.push(connectionInfo);

return connections;
};
Expand Down Expand Up @@ -198,5 +182,8 @@ internals.formatDescription = function (description) {

description = description || '';
description = Chalk.yellow(description);

return description;
};

exports.pkg = Pkg;

0 comments on commit 0143f72

Please sign in to comment.