mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 20:52:08 +08:00
Add X-Count header when slicing collection
This commit is contained in:
@ -36,6 +36,9 @@ routes.list = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_start) {
|
if (_start) {
|
||||||
|
res.setHeader('X-Count', resource.length)
|
||||||
|
res.setHeader('Access-Control-Expose-Headers', 'X-Count')
|
||||||
|
|
||||||
resource = resource.slice(_start, _end)
|
resource = resource.slice(_start, _end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,11 @@ describe('Server', function() {
|
|||||||
.get('/comments?_start=1&_end=2')
|
.get('/comments?_start=1&_end=2')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(low.db.comments.slice(1, 2))
|
.expect(low.db.comments.slice(1, 2))
|
||||||
.expect(200, done)
|
.expect(200)
|
||||||
|
.end(function(err, res){
|
||||||
|
assert.equal(res.headers['x-count'], 5)
|
||||||
|
done()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user