lib/ahc_helper.rb in ahc-0.3.0 vs lib/ahc_helper.rb in ahc-0.3.1
- old
+ new
@@ -1,5 +1,8 @@
+require 'net/http'
+require 'uri'
+
module AhcHelper
def render_ahc(template)
if params[:format] == 'json'
render json: @data
@@ -17,8 +20,30 @@
controller = params[:controller].split('/').last
action = params[:action]
@data ||= {}
@data['resources'] = collection
render_ahc("#{controller}/#{action}")
+ end
+
+end
+
+class AhcProxy
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ request = Rack::Request.new(env)
+ path = request.fullpath
+ if path.start_with?('/s/') || path.start_with?('/static/') || path.start_with?('/plovr/')
+ begin
+ response = Net::HTTP.get(URI.parse("http://#{Ahc.host || Ahc.default_host}:#{Ahc.port || Ahc.default_port}" + path))
+ return [200, {}, [response]]
+ rescue
+ return [200, {}, ['Ahc server is not running']]
+ end
+ end
+ @app.call(env)
end
end