Connection refused when using Rack Proxy

I’m trying to catch all *.dev requests on port 80 and send them to the
right Rack project by using Rack Proxy. I’m able to catch the requests
and based on the URI I’ll look for a config.ru in a specific folder.
When I’m able to find one I’ll boot up the server on port 3000.

After that, whenever I recieve a request on port 80, I try to set the
HTTP_HOST to localhost:3000, but I’m getting the message Unexpected
error while processing request: Connection refused - connect(2) for
“localhost” port 3000. I am able to access the application through
localhost:3000, but not through a *.dev domain. I already tried using
different ports, but that’s not working either, so I guess it has
something to do with the user that’s running it. However, I hope someone
can help me with this.

require ‘rack-proxy’

class AppProxy < Rack::Proxy
def rewrite_env(env)
request = Rack::Request.new(env)
site = request.host[0…-5]
uid = File.stat(FILE).uid

path = Etc.getpwuid(uid).dir + '/Software/Applications/'

front_controller = "#{path}#{site}/config.ru"
if File.file?(front_controller)

 system "rackup -p 3000 -D #{front_controller} "
 env["HTTP_HOST"] = "localhost:3000"

else
raise Exception.new “Not found”
end

env
end
end

run AppProxy.new

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs