E 'possibile fare. Ecco la documentazione https://github.com/hapijs/good/blob/master/API.md#stream-transforms-using-plugin-configs
Hapi configurazione percorso
var routeConfig = {
plugins: {
good: {
suppressResponseEvent: true
}
}
};
server.route({
method: '*',
path: '/suscribe/{path*}',
handler: function(req, rep){
rep("OK!");
},
config: routeConfig
});
Creazione di un filtro personalizzato per buona. Dovrai creare un nuovo pacchetto npm. Per questo esempio, ci accingiamo a nominarlo buon filtro Seguire l'architettura da https://github.com/hapijs/good-squeeze/ Il file principale (index.js) contiene:
'use strict';
module.exports = {
Filter: require("./filter.js")
};
Questo pacchetto deve essere disponibile quando buona sta caricando. Il codice seguente va in filter.js nel buon filtro pacchetto.
'use strict';
const Stream = require('stream');
class Filter extends Stream.Transform {
constructor(options) {
options = Object.assign({}, options, {
objectMode: true
});
super(options);
}
_transform(data, enc, next) {
if (data.event === 'response' && data.config.suppressResponseEvent === true) {
return next();
}
return next(null, data);
}
}
module.exports = Filter;
Infine, aggiungere il filtro per buona configurazione.
const options = {
ops: {
interval: 1000
},
reporters: {
myConsoleReporter: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ log: '*', response: '*' }]
},
{
module: 'good-filter',
name: 'Filter',
args: [{ log: '*', response: '*' }]
},
{
module: 'good-console'
}, 'stdout']
}
};
Miglior risposta finora, grazie! – victorkohl