mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 20:52:08 +08:00
Add 404 for GET /:resource
This commit is contained in:
@ -41,6 +41,11 @@ module.exports = function(source) {
|
|||||||
// GET /*?*&_end=
|
// GET /*?*&_end=
|
||||||
// GET /*?*&_start=&_end=
|
// GET /*?*&_start=&_end=
|
||||||
function list(req, res, next) {
|
function list(req, res, next) {
|
||||||
|
// Test if resource exists
|
||||||
|
if (!db.object.hasOwnProperty(req.params.resource)) {
|
||||||
|
return res.sendStatus(404)
|
||||||
|
}
|
||||||
|
|
||||||
// Filters list
|
// Filters list
|
||||||
var filters = {}
|
var filters = {}
|
||||||
|
|
||||||
|
@ -59,6 +59,12 @@ describe('Server', function() {
|
|||||||
.expect(db.posts)
|
.expect(db.posts)
|
||||||
.expect(200, done)
|
.expect(200, done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should respond with 404 if resource is not found', function(done) {
|
||||||
|
request(server)
|
||||||
|
.get('/undefined')
|
||||||
|
.expect(404, done)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('GET /:resource?attr=&attr=', function() {
|
describe('GET /:resource?attr=&attr=', function() {
|
||||||
|
Reference in New Issue
Block a user