Skip to content

Commit 43869ff

Browse files
committed
Tweak table() api. Closes hapijs#2262
1 parent 3805c1f commit 43869ff

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

lib/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,10 @@ internals.Plugin.prototype.state = function (name, options) {
416416

417417
internals.Plugin.prototype.table = function (host) {
418418

419-
var table = {};
419+
var table = [];
420420
for (var i = 0, il = this.connections.length; i < il; ++i) {
421421
var connection = this.connections[i];
422-
table[connection.info.uri] = connection.table(host);
422+
table.push({ info: connection.info, labels: connection.settings.lables, table: connection.table(host) });
423423
}
424424

425425
return table;

test/connection.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ describe('Connection', function () {
598598
server.route({ path: '/test/', method: 'get', handler: function () { } });
599599
server.route({ path: '/test/{p}/end', method: 'get', handler: function () { } });
600600

601-
var routes = server.table()[server.info.uri];
601+
var routes = server.table()[0].table;
602602

603603
expect(routes.length).to.equal(2);
604604
expect(routes[0].path).to.equal('/test/');
@@ -630,7 +630,7 @@ describe('Connection', function () {
630630
server.route({ path: '/test/', vhost: 'two.example.com', method: 'get', handler: function () { } });
631631
server.route({ path: '/test/{p}/end', method: 'get', handler: function () { } });
632632

633-
var routes = server.table()[server.info.uri];
633+
var routes = server.table()[0].table;
634634

635635
expect(routes.length).to.equal(4);
636636
done();
@@ -646,7 +646,7 @@ describe('Connection', function () {
646646
server.route({ path: '/test/', vhost: 'two.example.com', method: 'get', handler: function () { } });
647647
server.route({ path: '/test/{p}/end', method: 'get', handler: function () { } });
648648

649-
var routes = server.table('one.example.com')[server.info.uri];
649+
var routes = server.table('one.example.com')[0].table;
650650

651651
expect(routes.length).to.equal(3);
652652
done();
@@ -662,7 +662,7 @@ describe('Connection', function () {
662662
server.route({ path: '/test/', vhost: 'two.example.com', method: 'get', handler: function () { } });
663663
server.route({ path: '/test/{p}/end', method: 'get', handler: function () { } });
664664

665-
var routes = server.table(['one.example.com', 'two.example.com'])[server.info.uri];
665+
var routes = server.table(['one.example.com', 'two.example.com'])[0].table;
666666

667667
expect(routes.length).to.equal(4);
668668
done();
@@ -678,7 +678,7 @@ describe('Connection', function () {
678678
server.route({ path: '/test/', vhost: 'two.example.com', method: 'get', handler: function () { } });
679679
server.route({ path: '/test/{p}/end', method: 'get', handler: function () { } });
680680

681-
var routes = server.table('three.example.com')[server.info.uri];
681+
var routes = server.table('three.example.com')[0].table;
682682

683683
expect(routes.length).to.equal(2);
684684
done();
@@ -1083,7 +1083,7 @@ describe('Connection', function () {
10831083
}
10841084
]);
10851085

1086-
var table = server.table()[server.info.uri];
1086+
var table = server.table()[0].table;
10871087
var paths = table.map(function (route) {
10881088
var obj = {
10891089
method: route.method,

test/plugin.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,12 +2181,11 @@ describe('Plugin', function () {
21812181

21822182
internals.routesList = function (server, label) {
21832183

2184-
var table = server.select(label || []).table();
2185-
var connections = Object.keys(table);
2184+
var tables = server.select(label || []).table();
21862185

21872186
var list = [];
2188-
for (var c = 0, cl = connections.length; c < cl; ++c) {
2189-
var routes = table[connections[c]];
2187+
for (var c = 0, cl = tables.length; c < cl; ++c) {
2188+
var routes = tables[c].table;
21902189
for (var i = 0, il = routes.length; i < il; ++i) {
21912190
var route = routes[i];
21922191
if (route.method === 'get') {

0 commit comments

Comments
 (0)