DEV Community

Discussion on: Building with server-sent events with React and Node.js

Collapse
 
4shub profile image
Shubham Naik

Hi Bryan!

Sorry for the lack of response, I’d love to look at your code, send me a dm of your git repo and I’ll check it out if you’re still having this issue.

Collapse
 
bryanforst profile image
bryan forst

Its not up yet on git since its not working. also the repo is in another fellows name...
I started to try and solve the server-sent-events issues using express-sse.
That is throwing a 404 error. I will send you the stackoverflow question once i get it entered.

Thread Thread
 
bryanforst profile image
bryan forst

Finally decided to just do a specific implementation outside of my other project. I put it up as public at
github.com/bryanforst/sse-test

The client is still throwing a 404 error - odd thing is that its just showing localhost:3000 and not the endpoint /sseconnect.

I am sure its something stupid I am missing. Thanks for any advice you can give

Thread Thread
 
4shub profile image
Shubham Naik • Edited

I think you might be running two servers that are both fighting for port 3000. There is a server running hosting your react app and a server running hosting your SSE events.

There are two ways we can solve this problem:

  1. Changing one of the ports to a different port.
    This is pretty simple, just change the port of your SSE server to 3001 instead of 3000 and change the url you are connecting to to http://localhost:3001/server-sent-events-url

  2. Hosting the server code and the react code on the same server
    I think this article has some good info on running an express server with react.

dev.to/dan_mcm_/leveling-up-from-c...

I'll also see if I have some time to add a react example to this codebase so people can better try it out end to end with react.

Thread Thread
 
bryanforst profile image
bryan forst

Thanks Shubham,
Originally in my app the back end was listening on 5000 with the front end on 3000. When I attempted to set EventSource to the back end I was getting an error message. That confused me.

Indeed after setting the back end in my test to listen at 5000 all worked well.

Will try to integrate this into my main app.

Thanks for all your help so far
bryan

Thread Thread
 
4shub profile image
Shubham Naik

Perfect! Glad it worked out for you