How to deploy socketio applications

devloop01HOBBY

a year ago

Hello, I've never deployed a nodejs app before and I chose railway as a service to deploy a WebSocket app/game but it is not working.

The deployment is successful and there is no error but when I use the generated URL in my socketio client it returns cors issue. which is weird because I've setup cors on socketio config server

here is the repo: https://github.com/devloop01/p5-multiplayer-sketch/tree/main/server

I also tried to deploy another app without game logic but it is also not showing anything on the generated URL

here's the other repo: https://github.com/devloop01/express-socket-chat

Solved

14 Replies

a year ago

You are misinterpreting the error, your actual issue is not a CORS issue, a CORS error is just a side effect of the actual issue.

Please read this docs page -

https://docs.railway.app/guides/fixing-common-errors


Status changed to Solved railway[bot] 12 months ago


devloop01HOBBY

a year ago

I tried to fix the issues related to this article and pushed the code in GitHub but its still shows nothing if I visit the link: https://distinguished-learning-production.up.railway.app/

here is the updated server file: https://github.com/devloop01/p5-multiplayer-sketch/blob/main/server/src/index.ts


a year ago

The index.ts file now looks good now, how long ago did you generate that domain?


devloop01HOBBY

a year ago

I created that yesterday


devloop01HOBBY

a year ago

The index.ts file now looks good now, how long ago did you generate that domain?

can you check the other repo where I just did a basic express server that hosts a public folder and a basic socketio connection
the same thing is happening I cannot run the socket application. If I remove the socket code and just host the express server with the static folder it works


a year ago

Express and socketio need to listen on the same port.


devloop01HOBBY

a year ago

Express and socketio need to listen on the same port.

wait isn't httpServer.listen(port, ...) listening to the same port as socketio?


a year ago

For you other repo, you also need to read through the fixings common errors page.


devloop01HOBBY

a year ago

For you other repo, you also need to read through the fixings common errors page.

Hey, I seem to have fixed the issue by using the server that is returned from server.listen(port, ...), now I have configured the cors and also read the docs but in the frontend that is hosted on vercel I am getting cors issue which is kinda of weird because I have set the cors origin properly

https://p5-multiplayer-sketch.vercel.app/

https://github.com/devloop01/p5-multiplayer-sketch/blob/main/server/src/index.ts


devloop01HOBBY

a year ago

For you other repo, you also need to read through the fixings common errors page.

Hey, now it's working! ✨ finally

Maybe it takes some time to update the deployment which sucks 😢 (Is there any way to make it faster?)

Thanks for your help man!


a year ago

You only need to wait for the domain after you have generated it, otherwise it's not slow.


devloop01HOBBY

a year ago

You only need to wait for the domain after you have generated it, otherwise it's not slow.

so do I need to regenerate the domain on every build? after it showed deployed it took like 3-5 mins


a year ago

so do I need to regenerate the domain on every build?

No you don't, I'm not sure where you got that notion from.

after it showed deployed it took like 3-5 mins

Could be due to your browsers cache, otherwise there's nothing to worry about.


devloop01HOBBY

a year ago

Got it mate! Thanks for helping