Ruby: How to serve static HTML and an EventMachine WebSocket server from the same application?

760 views Asked by At

I'm writing a simple chat application. The only "front-end" required is a single html file, a javascript file, and a few stylesheets. The majority of the application is the server-side EventMachine WebSocket server.

I'm also trying to host this on Heroku.

I currently have a sinatra app that just serves the static files, and a separate app that serves the WebSocket server (on a different port).

Is there a way I can combine these so that I can start up one application which serves/responds to port 80 (for the static files) and another port for the WebSocket server?

2

There are 2 answers

2
Joshua On

It's probably not a good idea to have your WebSocket server run on a different port. WebSockets run on port 80 specifically because that port is not blocked on most networks. If you use a different port, you will find users behind some firewalls unable to use your application.

Running your event server separate from your web server is probably the best way to go.

0
dj2 On

If you want something a bit more experimental, Goliath has WebSocket support in the master branch and can also serve the needed resources. If you look in the examples directory there is a WebSocket server that also serves it's HTML page.