-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
I've uploaded an example repo that demonstrates the issue (of which there are two):
https://github.com/Integralist/Sinatra-SSE
The first issue is that SSE doesn't appear to work when using JRuby, but it does work when using MRI (note: the above repo is set to use MRI so it should work; so make sure to switch to JRuby and reinstall dependencies before testing)
Run with rackup -p 8000 and then you'll be able to access the application via http://localhost:8000/.
The home page loads a JavaScript file that opens a connection to /healthcheck.
The /healthcheck endpoint gets passed an even object from /update. Where /update is a POST endpoint that receives JSON.
You can test this using something like:
curl -v -H "Content-Type: application/json" -X POST -d '{"foo":"bar"}' http://127.0.0.1:8000/update
There are no obvious errors when using JRuby. The errors reported by JavaScript aren't helpful either.
The output in the terminal (for JRuby) is:
Puma 2.10.2 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:8000
127.0.0.1 - - [14/Jan/2015:16:11:55 +0000] "GET / HTTP/1.1" 200 190 0.0960
127.0.0.1 - - [14/Jan/2015:16:11:55 +0000] "GET /assets/scripts/connection.js HTTP/1.1" 304 - 0.0080
127.0.0.1 - - [14/Jan/2015:16:11:55 +0000] "GET /healthcheck HTTP/1.1" 200 - 0.0200
127.0.0.1 - - [14/Jan/2015:16:11:57 +0000] "GET / HTTP/1.1" 200 190 0.0380
127.0.0.1 - - [14/Jan/2015:16:11:58 +0000] "GET /assets/scripts/connection.js HTTP/1.1" 304 - 0.0160
127.0.0.1 - - [14/Jan/2015:16:11:58 +0000] "GET /healthcheck HTTP/1.1" 200 - 0.0130
127.0.0.1 - - [14/Jan/2015:16:12:01 +0000] "GET /healthcheck HTTP/1.1" 200 - 0.0100
127.0.0.1 - - [14/Jan/2015:16:12:04 +0000] "GET /healthcheck HTTP/1.1" 200 - 0.0060
The browser displays something like:
:8000/healthcheck:1 GET http://localhost:8000/healthcheck net::ERR_CONNECTION_REFUSED
connection.js:12 error Event {clipboardData: undefined, path: NodeList[0], cancelBubble: false, returnValue: true, srcElement: EventSource…}
The second issue (with MRI) is a random error that is reported:
NoMethodError: undefined method `join' for #<String:0x007f8cb19bee58>
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:37:in `rescue in call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/urlmap.rb:66:in `block in call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/urlmap.rb:50:in `each'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/urlmap.rb:50:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/tempfile_reaper.rb:15:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/lint.rb:49:in `_call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/lint.rb:37:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/showexceptions.rb:24:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/commonlogger.rb:33:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:217:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/chunked.rb:54:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/content_length.rb:15:in `call'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/thin-1.6.3/lib/thin/connection.rb:86:in `block in pre_process'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `catch'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `pre_process'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/thin-1.6.3/lib/thin/connection.rb:53:in `process'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/thin-1.6.3/lib/thin/connection.rb:39:in `receive_data'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/eventmachine-1.0.4/lib/eventmachine.rb:187:in `run_machine'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/eventmachine-1.0.4/lib/eventmachine.rb:187:in `run'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/thin-1.6.3/lib/thin/backends/base.rb:73:in `start'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/thin-1.6.3/lib/thin/server.rb:162:in `start'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/handler/thin.rb:19:in `run'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:286:in `start'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:147:in `start'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:147:in `start'
/Users/markmcdonnell/.gem/ruby/2.0.0/gems/rack-1.6.0/bin/rackup:4:in `<top (required)>'
/Users/markmcdonnell/.gem/ruby/2.0.0/bin/rackup:23:in `load'
/Users/markmcdonnell/.gem/ruby/2.0.0/bin/rackup:23:in `<main>'
...this error occurs every once in a while. I've yet to find any rhyme or reason behind it.