【发布时间】:2017-03-21 10:03:15
【问题描述】:
也在官方的 Restify repo 中询问:#1224
嗨,
是否有可能拥有一个可以处理任何未定义的接受类型的默认格式化程序。
例如:
restify.createServer({
formatters: {
'application/json': () => {},
// All other requests that come in are handled by this, instead of throwing error
'application/every-thing-else': () => {}
}
});
【问题讨论】:
-
当您尝试返回自定义模型时,您怎么能期望不必编写此代码?如果有帮助,默认格式化程序用于 application/octet-stream。
-
我之前并不清楚。更新了问题。我想要一个可以处理除重新设置默认格式化程序列表之外的任何内容的格式化程序。
-
是的,这正是我想要的。在我的例子中,所有的 mime 类型都只是具有不同属性集的 JSON 输出。
-
啊。我认为更好的标题是“设置默认格式化程序”,跳过问题的所有第一部分,只使用 restify 标签。
标签: restify