Fixed invalid json in API query results. Added total count in response header.

This commit is contained in:
Zaid Abdulla committed 2013-03-22 19:33:32 +03:00
1 parent bbbe881ca4
commit 52bbd6c4a0
1 file changed
+7 -5
+7 -5
View File
@@ -323,17 +323,19 @@ else
cur.skip(parseInt(urlParts.query.skip)) if urlParts.query.skip?
cur.limit(parseInt(urlParts.query.limit)) if urlParts.query.limit?
response.writeHead(200, {'Content-Type' : 'application/json'})
cur.count((err, total) ->
response.writeHead(200, {'Content-Type' : 'application/json', 'total' : total})
response.write("[\n")
i = 0
cur.each((err, item) ->
if item is null
response.end(']')
response.end("\n]")
else
response.write(",\n") if i++
addAliases(item) if collectionName is 'devices'
response.write(JSON.stringify(item) + ",\n")
response.write(JSON.stringify(item))
)
)
return
else
response.writeHead 404
response.end('404 Not Found')