DEV Community

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

 
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