Currently I have a Sinatra web app & a Grape API, the idea being to implement the Sinatra app in such a way that the web app is just another API consumer.
In my config.ru I have this:
run Rack::Cascade.new [API, Application]
API
is the Grape app & Application
is the Sinatra app. I am using open-uri to try to grab the JSON from the Grape api in a Sinatra route. I am using thin. I am omitting the /uri after the port number for ease of reading, the Grape & Sinatra apps work independently, I will explain further in a moment
open("http://localhost")
returns:
#<StringIO:0x007fbeab1b2e68
@base_uri=#<URI::HTTP:0x007fbeab1d47e8 URL:http://localhost>,
@meta=
{"content-type"=>"text/html; charset=utf8",
"x-pow-template"=>"welcome",
"date"=>"Fri, 06 Sep 2013 07:29:15 GMT",
"connection"=>"keep-alive",
"transfer-encoding"=>"chunked"},
@status=["200", "OK"]>
However, if I open("http://localhost:9292")
the application hangs. I feel like maybe something is blocking I/O, like perhaps its waiting for itself to connect to itself but I am not sure enough of whats going on under the hood to really be sure.
If I point pow at it, spin it up at project.dev
& then spin it up with rackup
so I have two instances I can use open("http://project.dev/what/ever/url/i_need")
& it works like a charm. So the problem seems to be somewhere in pointing open-uri at itself... I think...
Is this because of the Rack::Cascade
? is this a problem with thin
? or maybe the with open-uri
? Is this just completely the wrong way to approach this problem?
I am open to just about any solution however I would prefer to keep it as simple as possible, with minimal external requires as I intent to use this pattern frequently.
Let me know if any additional information is required & I will do my best to provide it.
It appears that sinatra and open-uri step over each other, as I faced the same issue with sinatra 1.4.4 using different servers (puma, webrick, thin).
My solution was to switch to
curb
and this solved the problem.