CouchDB:使用CouchApp中的http请求获取服务器时间

juk*_*pff 5 time couchdb gettime couchapp

我需要在CouchApp中使用"user-is-online"统计信息的服务器时间.我使用jquery.couch.js并且更喜欢有一个url,例如/ db/_design/app/time - 这会给我一个时间戳.我怎么知道这个?

Jas*_*ith 5

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
           };
}
Run Code Online (Sandbox Code Playgroud)

服务器还包括Date您可能要使用的标头.

$ 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"}
Run Code Online (Sandbox Code Playgroud)