Is there a way (or could one be added) to listen for an event/hook for when Nuxt is about to return the response to the browser?
The reason being, I'm using sockets server-side. In a browser, the socket will automatically be disconnected on page unload. This doesn't happen server-side, so every new page request leaves orphaned socket connections. Ideally, I'd listen for an event/hook that knew we were finished with the socket, and disconnect. Currently, I'm using setTimeout
to disconnect the socket (only for process.server
). It works, but it feels dirty, and possibly error prone.
By the way, I've looked into using a module and listening for render:route
, but it's unclear if that happens at the appropriate lifecycle point (actual documentation would be helpful here), nor am I aware of how to access the apollo clients from there (which is what I'm using for the socket).