我的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