-1

I have a ruby application in which I am using puma web server which listens on port 8008.

Now I have got requirement to implement socket.io/websockets.

I was exploring the possibility of using EventMachine::WebSocket but since my puma application is already using port 8008, I cannot bind to 8008.

My UI is written in javascript and puma application basically exposes rest endpoints.

How can I implement websockets in such a scenario?

Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59
Chirayu Sharma
  • 75
  • 1
  • 11

1 Answers1

1

I'd leave the Rails server on the port it's running on, and redirect your websocket requests to the other server which runs on a different port.

This question/answer essentially describes the implementation. So you'd probably want something like:

match "/websocket/(*path)" => redirect {|params, req| "http://your.domain:8009/#{params[:path]}"}

where 8009 is the port your Websocket server runs on.

James Balazs
  • 88
  • 1
  • 4