在 JSON/View in onPreResponse in happy.js 之间切换
Switch between JSON / View in onPreResponse in Hapi.js
>我正在尝试根据URL发送响应。想检查是否可以在 onPreResponse 中检查 url 并发送响应。这是我想做的事情。
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 使用视图进行渲染
如果我正确理解你的问题,为什么你不能定义两条路线?
[{
method: 'GET',
path:'/',
handler: function (request, reply) {
reply.view('layout', request.response.source);
}
},
{
method: ['GET','POST'],
path:'/api',
handler: function (request, reply) {
reply(result);
}
}]
相关文章:
- 重构 jQuery in JS 问题
- IFrame for IOS in JS
- Url.RouteUrl in js
- RSACryptoServiceProvider equivalent in JS
- AngularJS Elements in JS iframe1.location.href
- Ruby array to js array in .js.erb file on rails
- Fomat day YYYY-MM-DDTHH:MM:SSZ in js
- JSON.stringify in js
- mysql password() in js
- Implementing vector in js
- Rails 3.2+jQuery+render partial in js.erb=损坏的HTML元素
- Ruby in JS in HAML:语法是什么?
- can't declare var a = 023; in js
- Negative lookbefore in js
- Rails 3.1 - JS - Socket.Io-emit in *.js.erb不被执行,并阻止jQuery-Fu
- dynamic html in js with angularJS
- EnableValidator in JS
- u007F and uFFFF in JS RegExp
- .Jar file in JS
- Subtract month from 'yyyymm' in js