Server sent events
Answered
Polar bear posted this in #help-forum
Polar bearOP
Is it possible to create a realtime using server sent events in nextjs?
If it is, is there a library or guide on this topic?
If it is, is there a library or guide on this topic?
Answered by B33fb0n3
yes you can. But only with a serverfull enviorement. Nextjs itself works mostly via server functions and these will be run only for some seconds.
So create a serverfull enviorement and connect to it via a client (browser). Now you can send and retrieve events from the server
So create a serverfull enviorement and connect to it via a client (browser). Now you can send and retrieve events from the server
8 Replies
yes you can. But only with a serverfull enviorement. Nextjs itself works mostly via server functions and these will be run only for some seconds.
So create a serverfull enviorement and connect to it via a client (browser). Now you can send and retrieve events from the server
So create a serverfull enviorement and connect to it via a client (browser). Now you can send and retrieve events from the server
Answer
Polar bearOP
Isn't remix like nextjs run for some seconds, I have made it in remix in the same app.
I don't fully understand what is
I don't fully understand what is
serverfull
, do you mean I need to create another server like a node app server?nextjs functions run only for a few seconds. But you want a constant connection. Not a connection that least only a few seconds. When deploying on vercel for example you only get a serverless enviorement (as said: function that only run for a few seconds). A serverfull enviorement is a real server, that holds your connections and stays online. That can be a VPS for example
Polar bearOP
Then the issue is where I will deploy it, not with the nextjs app
?
you can still deploy it on vercel, but the connection (where your client, your browser connects to) can't be to vercel. You need an extra server for that. That can be a VPS for example
Polar bearOP
Ok, thanks. I'll search that.
happy to help