यह करने के लिए संभव है। यहाँ प्रलेखन https://github.com/hapijs/good/blob/master/API.md#stream-transforms-using-plugin-configs
Hapi मार्ग विन्यास
var routeConfig = {
plugins: {
good: {
suppressResponseEvent: true
}
}
};
server.route({
method: '*',
path: '/suscribe/{path*}',
handler: function(req, rep){
rep("OK!");
},
config: routeConfig
});
अच्छा के लिए कस्टम फ़िल्टर बना रहे है। आपको एक नया एनपीएम पैकेज बनाना होगा। इस उदाहरण के लिए, हम इसे नाम के लिए अच्छा फिल्टर वास्तुकला https://github.com/hapijs/good-squeeze/ मुख्य फ़ाइल (index.js) से जा रहे हैं का पालन करें शामिल हैं: जब अच्छा
'use strict';
module.exports = {
Filter: require("./filter.js")
};
इस पैकेज उपलब्ध होना चाहिए लोड हो रहा है। निम्नलिखित कोड filter.jsअच्छा फिल्टर पैकेज में में चला जाता है।
'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;
अंत में, अच्छा विन्यास करने के लिए अपने फ़िल्टर जोड़ें।
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']
}
};
सर्वश्रेष्ठ उत्तर है, धन्यवाद:
का विन्यास
good
/good-squeeze
बाहर करने के लिए "health
":और फिर अपने मार्ग टैग करें! – victorkohl