我的CouchDB显示函数不会运行provide('json',...)函数。它会在某些情况下运行html提供。这里是显示功能:显示函数提供json
function(doc, req) {
provides('json', function(){
return {'json': doc };
});
provides('html', function(){
return "<html><body>html string here</body></html>";
});
return {'json': {
'hello': "goodbye"
}
};
}
这是发送文本/ x-json时的示例请求。你好:再见,也将返回如果我使用接受:应用/ JSON
[email protected]:~/py/liqc$ curl -i -H "Accept: text/x-json" http://127.0.0.1:8001/liqc/user-dave
HTTP/1.1 200 OK
Content-Length: 20
Vary: Accept
Server: CouchDB/1.0.2 (Erlang OTP/R14B)
ETag: "6V7EMSS64ZQ5SRLI0EYQVDWES"
Cache-Control: must-revalidate
Date: Mon, 27 Jan 2014 15:54:31 GMT
Content-Type: text/plain;charset=utf-8, text/x-json
{"hello":"goodbye"}
当我要求的text/html,我也得到打招呼:再见。如果我删除show函数的最终返回结果,应用程序/ json将继续给我你好:再见,但text/html会给我我想要的结果!
[email protected]:~/py/liqc$ curl -i -H "Accept: text/html" http://127.0.0.1:8001/liqc/user-dave
HTTP/1.1 200 OK
Content-Length: 42
Vary: Accept
Server: CouchDB/1.0.2 (Erlang OTP/R14B)
ETag: "9B8K3XGK28Y7RL2ART28WLL50"
Date: Mon, 27 Jan 2014 16:02:41 GMT
Content-Type: text/html; charset=utf-8
<html><body>html string here</body></html>
我做错了什么,或者这是与CouchDB的事情吗?我正在运行一个localhost反向代理到cloudant BTW。谢谢你的帮助。
感谢您的答复!从我看到的所有例子中,当使用provide时我并不认为我需要返回,但是我被卡住了。感谢您确认此处不应出现任何退货。另外,我不知道如何取消回归,仍然会问好:再见。如果我发送接受'text/x-json'或'application/json',我实际得到的是内容长度为0的响应。 – DaveEdelstein
知道没有回报的路,我搞砸了我提供的JSON函数一点点。如果我提供('json',function(){return {'body':toJSON(doc)};});这给了我正确的内容类型,并输出文档! – DaveEdelstein