Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/misc #759

Merged
merged 2 commits into from
Apr 12, 2013
Merged
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
5 changes: 4 additions & 1 deletion lib/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ var internals = {};
/*
var config = [{
pack: {
cache: 'redis'
cache: 'redis',
app: {
'app-specific': 'value'
}
}
servers: [
{
Expand Down
2 changes: 2 additions & 0 deletions lib/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ exports = module.exports = internals.Pack = function (options) {

this.list = {}; // Loaded plugins by name
this.events = new Events.EventEmitter(); // Consolidated subscription to all servers' events
this.app = options.app || {};

var cacheOptions = Catbox.defaults.apply(options.cache || Defaults.cache);
if (!options.cache ||
Expand Down Expand Up @@ -149,6 +150,7 @@ internals.Pack.prototype._register = function (plugin, permissions, options, cal

var methods = {
length: selection.servers.length,
app: self.app,

api: function (/* key, value */) {

Expand Down
9 changes: 5 additions & 4 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ internals.Request.prototype.log = function (tags, data, timestamp) {
this._logger.push(item);
this.server.emit('request', this, item, tagsMap);

if (data &&
this.server.listeners('request').length === 1 && // Pack always listening
if (this.server.listeners('request').length === 1 && // Pack always listening
this.server.settings.debug &&
this.server.settings.debug.request &&
Utils.intersect(tagsMap, this.server.settings.debug.request).length) {

console.error('Unmonitored error: ');
console.error(data.stack);
console.error('Unmonitored error: ' + item.tags.join(', '));
if (data) {
console.error(data instanceof Error ? data.stack : data);
}
}
};

Expand Down
7 changes: 5 additions & 2 deletions test/integration/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ describe('Composer', function () {

var manifest = {
pack: {
cache: 'memory'
cache: 'memory',
app: {
my: 'special-value'
}
},
servers: [
{
Expand Down Expand Up @@ -60,7 +63,7 @@ describe('Composer', function () {

composer._packs[0]._servers[0].inject({ method: 'GET', url: '/test1' }, function (res) {

expect(res.result).to.equal('testing123');
expect(res.result).to.equal('testing123special-value');
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pack/--test1/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var internals = {};

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

pack.select('test').route({ path: '/test1', method: 'GET', handler: function () { this.reply('testing123'); } });
pack.select('test').route({ path: '/test1', method: 'GET', handler: function () { this.reply('testing123' + ((pack.app && pack.app.my) || '')); } });
pack.api(internals.math);
pack.api('glue', internals.text.glue);

Expand Down
2 changes: 1 addition & 1 deletion test/integration/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ describe('Request', function () {
++prints;

if (prints === 1) {
expect(msg).to.equal('Unmonitored error: ');
expect(msg).to.equal('Unmonitored error: hapi, uncaught, handler, error');
}
else {
console.error = orig;
Expand Down
9 changes: 8 additions & 1 deletion test/unit/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,21 @@ describe('Request', function () {

it('doesn\'t throw an error when logging without data and debug is configured', function (done) {

var debugServer = new Hapi.server({ debug: { request: ['uncaught'] }});
var debugServer = new Hapi.server({ debug: { request: ['uncaught'] } });
var request = new Request(debugServer, _req, _res);

var fn = function () {

request.log('uncaught', null, Date.now());
};

var orig = console.error;
console.error = function (msg) {

expect(msg).to.equal('Unmonitored error: uncaught');
console.error = orig;
};

expect(fn).to.not.throw(Error);
done();
});
Expand Down