Next.js Discord

Discord Forum

How can an API route continue processing requests even if the user refreshes the page?

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
I've an next app with logic

(client) -> start long process, (streaming response)
(api route) -> got request, call another api with streaming and pipe to client
(another api) -> get request, send stream response to api route
(api route) -> process done, save information to db


However, when the process is ongoing and the client refreshes the page, the streaming on the API route stops, whereas it continues to run on another API. How can we ensure that the API route keeps processing requests even if the client refreshes the page?

3 Replies

American black bearOP
help 😦 stuck on this problem

i've many solution, but it should change own architecture

for example using message broker or web socket, need much effort to do that
Not sure if I'm understanding you correctly. There is a new feature coming with Next.js 15 which maybe what you are looking for https://rc.nextjs.org/docs/app/api-reference/functions/unstable_after
@Simon Knittel 🍹 Not sure if I'm understanding you correctly. There is a new feature coming with Next.js 15 which maybe what you are looking for https://rc.nextjs.org/docs/app/api-reference/functions/unstable_after
American black bearOP
thanks for the response, i've solution with this problem

just call the next api from the another api as a different request to save the result

so the logic look like

(client) -> start long process, (streaming response)
(api route /generate) -> got request, call another api with streaming and pipe to client
(another api) -> get request, send stream response to api route

when it has done
(another api) call next api and send the result
(api route /save) save the result into database