Friday, 6 September 2013

Can open-uri be used across rack applications?

Can open-uri be used across rack applications?

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.
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.

No comments:

Post a Comment