简体   繁体   中英

How to initialize a Websocket on existing port in Puma server?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM