javascript - Hapijs onPreResponse, forwarded response -
for api need have md5 result routes, use:
server.ext('onpreresponse', function(request, reply) { var content = request.response.source; var code = request.response.statuscode; if(typeof request.headers.md5 != 'undefined' && code == 200) { content = md5(content); } if(!debug && code != 200){ content = "error"; } reply(content).code(code); });
when response 404 error, request.response
doesn't have response.statuscode
... can handle with:
if(typeof code == 'undefined'){ code = 404; }
but when try view documentation generated lout, have this:
how can forward code message?
you want use reply.continue()
rather reply().code()
a similar question answered here: https://github.com/hapijs/discuss/issues/103