How to cancel a server fetch call to a remote endpoint?
Hey guys,
I need a way to cancel a request made from nitro to multiple external dotnet core apis - and I didn't find a way to "forward" the cancellation from the the nuxt frontend to the nuxt/nitro backend.
Can anyone help me? Is this even possible?
Background: The endpoints do some complex longer running tasks and it would be awesome if the get cancelled (as they normally would if the calling end closes/ends the connection)
1 Reply
thanks @L422Y for your reply!
I already tried the abortController, which works to a certain way, BUT
The problem I am facing is that I don't want to cancel every previous request if a new one comes in (because this would led to issues between different instances calling the nuxt api) - just the cancellation from the current fetch should be aborted if it is cancelled from outside.
I tried
event.node.req.on
handler,but these are also coming after the request finished and not when it got cancelled already
Found an issue, but closed: https://github.com/nuxt/nuxt/issues/22684 which leds to https://github.com/unjs/unenv/issues/153 which is still openGitHub
AbortController does not abort $fetch request when invoked server-s...
Environment Operating System: Linux Node Version: v18.16.0 Nuxt Version: ^3.6.5 Nitro Version: - Package Manager: [email protected] Builder: webpack User Config: devtools Runtime Modules: - Build Modules: ...
GitHub
support abort
signal
for direct fetch util · Issue #153 · unjs/un...Describe the feature See: nuxt/nuxt#22684 We don't yet support AbortController meaning that the fetch created with createFetch does not have a way to cancel requests. This may be desirable, dep...