SSE With EventSource
Answered
Podenco Valenciano posted this in #help-forum
Podenco ValencianoOP
I am building an application where I need my client side and server side to communicate. In the server, I am polling an API by sending GET requests, and sending the responses to the client side to update the props there, which then populate the front end in real time.
I am doing this with the following within the client side:
Whenever I am on local, the workflow works without any issues. Whenever I deploy to Vercel, my EventSource fails out, and the Vercel logs say that there has been a timeout at the endpoint that I am hitting.
How can I get the following code structure to work?
I am doing this with the following within the client side:
const eventSource = new EventSource(/api/getApples/${response.id});
eventSource.onmessage = function (event) { ... }.Whenever I am on local, the workflow works without any issues. Whenever I deploy to Vercel, my EventSource fails out, and the Vercel logs say that there has been a timeout at the endpoint that I am hitting.
How can I get the following code structure to work?
7 Replies
Podenco ValencianoOP
Is there a simple workaround?
There are no workarounds at all. Vercel doesn’t support long-running processes, so you simply can not host anything long-running, like SSE and ws, on Vercel
Either use a third party sse/ws provider, or self-host in your own server
Podenco ValencianoOP
Do you have a link or a brief explanation of the workflow of using a third party SSE?
It depends on that third party provider. But I have never used one, so you have to look them up and check their documentation.
A pretty popular real-time data provider is Pusher, though I haven’t used it myself so don’t know if it supports SSE or only websocket
A pretty popular real-time data provider is Pusher, though I haven’t used it myself so don’t know if it supports SSE or only websocket
Greek Harehound
@Podenco Valenciano stop working on THAT