问题描述
||
我需要在CouchApp中获取“用户在线”统计信息的服务器时间。我使用jquery.couch.js并希望有一个网址,例如/ db / _design / app / time-给我一个时间戳。
我怎么知道的?
解决方法
show函数可以做到这一点:
function(doc,req) {
// _design/myapp/_show/now
// First version possibly incompatible with some spidermonkey versions.
//var now = new Date();
var now = new Date().getTime();
var output = JSON.parse(JSON.stringify(now)) + \"\\n\";
return { code: 200,headers: { \"Content-Type\": \"text/plain\"
},body:output
};
}
服务器还包括您可能要使用的“ 1”头。
$ curl -D- http://localhost:5984
HTTP/1.1 200 OK
Server: CouchDB/1.1.0 (Erlang OTP/R14B)
Date: Fri,27 May 2011 00:28:31 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 40
Cache-Control: must-revalidate
{\"couchdb\":\"Welcome\",\"version\":\"1.1.0\"}