gpt4 book ai didi

content-type - Feathers 中的任意响应内容类型

转载 作者:行者123 更新时间:2023-12-02 20:18:59 25 4
gpt4 key购买 nike

我有一项自定义服务,必须以 CSV 格式返回数据。

我无法使用标准 Express 路由,因为我需要在此端点上使用 Feathers 的 Hook 。

我找不到返回非 HTML、非 JSON 数据的 Feathers 服务的示例,并且找不到指定响应内容类型的方法。

使用res.set('Content-Type', 'text/csv')从服务返回之前方法不起作用;决赛Content-Type header 已重置为 application/json ,即使该方法的返回值是常规字符串。

如何在 Feathers 的自定义服务方法中正确设置任意响应内容类型?

最佳答案

您可以像这样自定义响应格式:

const feathers = require('feathers');
const rest = require('feathers-rest');

const app = feathers();

function restFormatter(req, res) {
res.format({
'text/plain': function() {
res.end(`The Message is: "${res.data.text}"`);
}
});
}

app.configure(rest(restFormatter));

完整的文档可以在 here 找到.

使用您的own service specific middleware发送响应也应该可以。

关于content-type - Feathers 中的任意响应内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40169827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com