【发布时间】:2014-09-06 21:44:47
【问题描述】:
我想在我的 hapi 路由中进行内容协商,以便我可以返回客户端可以接受的数据类型。
有了快递,我会做这样的事情
res.format({
"text/plain": function(){
res.send("Text Response");
},
"text/html": function(){
res.send("HTML Response");
},
"application/json": function(){
res.json({ message: "JSON Response" });
},
"default": function() {
// log the request and respond with 406
res.status(406).send("Not Acceptable");
}
});
是否有内置方法可以使用 hapi 执行此操作?我查看了API docs 并没有看到任何东西。我是否被困在自己的解决方案中?
【问题讨论】:
-
希望能回答你的问题,github.com/hapijs/hapi/issues/252
-
谢谢。我想我得自己动手了。
标签: javascript node.js content-negotiation hapijs