Support for querying with HTTP HEAD requets to fetch only meta info like result count without returning all results.
This commit is contained in:
1 parent
13da4dc2da
commit
c0a181ef2b
1 file changed
+5
-2
+5
-2
@@ -275,8 +275,8 @@ else
|
|||||||
)
|
)
|
||||||
else if QUERY_REGEX.test(urlParts.pathname)
|
else if QUERY_REGEX.test(urlParts.pathname)
|
||||||
collectionName = QUERY_REGEX.exec(urlParts.pathname)[1]
|
collectionName = QUERY_REGEX.exec(urlParts.pathname)[1]
|
||||||
if request.method isnt 'GET'
|
if request.method not in ['GET', 'HEAD']
|
||||||
response.writeHead 405, {'Allow' : 'GET'}
|
response.writeHead 405, {'Allow' : 'GET, HEAD'}
|
||||||
response.end('405 Method Not Allowed')
|
response.end('405 Method Not Allowed')
|
||||||
return
|
return
|
||||||
collection = db["#{collectionName}Collection"]
|
collection = db["#{collectionName}Collection"]
|
||||||
@@ -316,6 +316,9 @@ else
|
|||||||
cur.limit(parseInt(urlParts.query.limit)) if urlParts.query.limit?
|
cur.limit(parseInt(urlParts.query.limit)) if urlParts.query.limit?
|
||||||
cur.count((err, total) ->
|
cur.count((err, total) ->
|
||||||
response.writeHead(200, {'Content-Type' : 'application/json', 'total' : total})
|
response.writeHead(200, {'Content-Type' : 'application/json', 'total' : total})
|
||||||
|
if request.method is 'HEAD'
|
||||||
|
response.end()
|
||||||
|
return
|
||||||
response.write("[\n")
|
response.write("[\n")
|
||||||
i = 0
|
i = 0
|
||||||
cur.each((err, item) ->
|
cur.each((err, item) ->
|
||||||
|
|||||||
Reference in new issue
Block a user