smocks
smocks copied to clipboard
When using Smocks.plugin onRequest the reply object doesn't get properly wrapped
When using Smocks.plugin onRequest the reply object doesn't get properly wrapped.
Smocks.plugin({
onRequest: function (request, reply, next) {
reply.redirect(path).send();
next();
},
onResponse: function (request, response) {
console.log('onResponse:');
}
});
Using reply.redirect() gives a internal imeplementation error at this line:
https://github.com/jhudson8/smocks/blob/master/hapi.js#L158
With the error:
Debug: internal, implementation, error
Object.Smocks.plugin.onRequest (/Users/dklever/Documents/Development/Repositories/shifu/lib/utils/shifu-server-plugins.js:18:68),handlePlugins (/Users/dklever/Documents/Development/Repositories/shifu/node_modules/smocks/hapi.js:158:36)
When using Smocks.plugin - onRequest we never get to this line when wrapping the reply object: https://github.com/jhudson8/smocks/blob/master/hapi.js#L163
Though when using the reply object directly from a handler within smocks.route() smocks wraps it and it works fine via this code:
https://github.com/jhudson8/smocks/blob/master/hapi.js#L163
So it could be that when it’s treated as a plugin there is something missing in the wrapping logic. To get around this I use a hapi server extension instead:
server.ext('onRequest', function(request, reply) {
console.log('TEST');
});