json-server
json-server copied to clipboard
Multiple DELETE requests crash server
db.json
{ "cart": [ { "id": 100, "count": 1 }, { "id": 101, "count": 1 } ] }
request
const url = 'http://localhost:3000/cart/'
const ids = [100, 101]
const deleteAll = ids.map(id => fetch(url + id, { method: 'DELETE' }))
Promise.all(deleteAll).then(result => console.log(result))
console
GET /cart 200 14.438 ms - 80
DELETE /cart/100 200 5.150 ms - 2
DELETE /cart/101 200 4.082 ms - 2
./src/api/db.json has changed, reloading...
Loading ./src/api/db.json
./src/api/db.json has changed, reloading...
Done
Resources
http://localhost:3000/cart
Home
http://localhost:3000
./src/api/db.json has changed, reloading...
Loading ./src/api/db.json
./src/api/db.json has changed, reloading...
Done
Resources
http://localhost:3000/cart
Home
http://localhost:3000
Cannot bind to the port 3000. Please specify another port number either through --port argument or through the json-server.json configuration file
Items are removed successfully but the server crashes. Not sure if something wrong with my code or it's a bug.
I think it's a bug. I found that making more than 3 delete requests per second causes the server to crash.
it happens with me also, did you solve it and how about custom endpoint delete all ?
I also had this problem, and solved it by removing the watch flag when starting json-server. This way the server doesn't reload automatically and all the requests are successfully handled.