Fixed invalid json in API query results. Added total count in response header.
This commit is contained in:
1 parent
bbbe881ca4
commit
52bbd6c4a0
1 file changed
+12
-10
+12
-10
@@ -323,17 +323,19 @@ else
|
|||||||
|
|
||||||
cur.skip(parseInt(urlParts.query.skip)) if urlParts.query.skip?
|
cur.skip(parseInt(urlParts.query.skip)) if urlParts.query.skip?
|
||||||
cur.limit(parseInt(urlParts.query.limit)) if urlParts.query.limit?
|
cur.limit(parseInt(urlParts.query.limit)) if urlParts.query.limit?
|
||||||
|
cur.count((err, total) ->
|
||||||
response.writeHead(200, {'Content-Type' : 'application/json'})
|
response.writeHead(200, {'Content-Type' : 'application/json', 'total' : total})
|
||||||
response.write("[\n")
|
response.write("[\n")
|
||||||
cur.each((err, item) ->
|
i = 0
|
||||||
if item is null
|
cur.each((err, item) ->
|
||||||
response.end(']')
|
if item is null
|
||||||
else
|
response.end("\n]")
|
||||||
addAliases(item) if collectionName is 'devices'
|
else
|
||||||
response.write(JSON.stringify(item) + ",\n")
|
response.write(",\n") if i++
|
||||||
|
addAliases(item) if collectionName is 'devices'
|
||||||
|
response.write(JSON.stringify(item))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return
|
|
||||||
else
|
else
|
||||||
response.writeHead 404
|
response.writeHead 404
|
||||||
response.end('404 Not Found')
|
response.end('404 Not Found')
|
||||||
|
|||||||
Reference in new issue
Block a user