0
我試圖根據URL發送響應。希望檢查是否可以檢查網址並在onPreResponse中發送回覆。這是我想要做的事情。在Hapi.js的onPreResponse中切換JSON /查看
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();
});
如何分辨高致病性禽流感如果我正確理解你的問題使用視圖渲染
爲什麼這必須在'onPreResonse'內?任何不使用標準路由功能的理由(即路徑爲'/ api/{path *}'的路徑)? –
這是一個好主意。一個例子,將不勝感激。 –
我需要看到更多的代碼才能明白你想要達到的目標。 –