我正在尝试根据网址发送回复。想检查是否可以检查网址并在onPreResponse上发送回复。这是我想要做的事情。
server.ext('onPreResponse', function (request, reply) {
if (request.path.indexOf('/api') > -1 ) {
// Do nothing. Let the response go as JSON
} else {
// Send back html by populating json data into
// handlebar template
reply.view('layout', request.response.source); // Need replacement for this
}
reply.continue();
});
如何告诉HAPI使用视图进行渲染
答案 0 :(得分:0)
如果我理解你的问题,为什么你不能定义两条路线?
[{
method: 'GET',
path:'/',
handler: function (request, reply) {
reply.view('layout', request.response.source);
}
},
{
method: ['GET','POST'],
path:'/api',
handler: function (request, reply) {
reply(result);
}
}]