Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

DELETE requests from Nuxt API endpoints return 500 Internal server error #440

Closed
serhii-chernenko opened this issue Jan 27, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@serhii-chernenko
Copy link

serhii-chernenko commented Jan 27, 2025

Describe the bug
I prepared a new repo for the previous issue: #439:
https://github.com/serhii-chernenko/nuxthub-issue

It's just a simple items list. It uses NuxtHub KV storage (but I guess it doesn't matter for the current issue).

I have 3 types of API endpoints:

  • GET — to fetch all items from the storage
  • PUT — to push a new item to the storage
  • DELETE — to delete an item from the storage.

The first two work as expected. DELETE works correctly locally even with remote: true option. But on the production URL it just returns this error:
Image
Image
Image

I tried to add a trick in the index.delete.ts endpoint file, but it didn't help:

setResponseStatus(event, 201, item)

return item

Steps to reproduce
It could be reproduced in the production domain:
https://nuxthub-issue.pages.dev/

Steps to reproduce the behavior:

  1. Fork the repo: https://github.com/serhii-chernenko/nuxthub-issue.
  2. Install the project.
  3. Open a built production URL.
  4. Create an item if the item’s list is empty.
  5. Try to delete any item from the list.
  6. Get 500 error.

Expected behavior
DELETE requests work the same way as GET and PUT

Notes
I suspect it's a Cloudflare issue, but I didn't find a quick solution. Anyway, it's built via Nitro preset and related to Nuxt ecosystem at all. I truly appreciate it if you can help solve the issue.

@serhii-chernenko serhii-chernenko added the bug Something isn't working label Jan 27, 2025
@serhii-chernenko serhii-chernenko changed the title DELETE requests return 500 Internal server error DELETE requests from Nuxt API endpoints return 500 Internal server error Jan 27, 2025
@serhii-chernenko
Copy link
Author

I replaced index.delete.ts with [id].delete.ts and passed the item id via URL:

await $fetch(`/api/v1/items/${item.id}`, {
  method: 'delete',
})

instead of

await $fetch('/api/v1/items', {
  method: 'delete',
  body: { id: item.id }
})

https://github.com/serhii-chernenko/nuxthub-issue/blob/main/src/layers/core/data/pages/index.vue#L75

My bad, perhaps it's my gap in knowledge, but I didn't find any related info in Nuxt docs that it's not allowed this way. Anyway, I'm going to close the issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant