问题
My aim is to do some automated testing over HTTP and HTTPS/SSL, via Rack, without recourse to a proxy server setup or anything like that. I have a gem that I want to test and I'd like for others to be able to run tests on too, so I'd like it to be as self contained as possible.
The code for App runs fine when run on it's own, so it's not included here, the problem is with the Rack part.
I'd like to do something like this:
app = Rack::Builder.app do
map "/" do
Rack::Handler::WEBrick.run App, Port: 3000
end
map "/ssl" do
Rack::Handler::WEBrick.run App, Port: 3001 # more options for SSL here...
end
end
run app
I've tried several combinations of the code above, like:
http = Rack::Builder.app do
map "/" do
run App
end
end
https = Rack::Builder.app do
map "/ssl" do
run App
end
end
Rack::Handler::WEBrick.run http, Port: 3000
Rack::Handler::WEBrick.run https, Port: 3001 # more options for SSL here...
With the two server setup up I tend to get one server run on the first port listed, then on interrupt it will run the second server on the next port listed - and then, on the next interrupt, either another server on 9292 or it shuts down.
I'm obviously doing something not quite right.
This is quite close, but ends up running the two servers via two different command line commands: Starting thin server on different ports
Any help is much appreciated.
回答1:
Current Thin does not support this -- I checked the source code.
Thin v2 is still pre-release, but the config code looks like it supports this via declaring multiple listeners in the config file.
But Thin v2 is still alpha software.
You can also switch to another server like Unicorn that does explicitly support binding to multiple ports or addresses.
来源:https://stackoverflow.com/questions/10755571/how-to-use-rack-map-to-run-two-thin-or-other-servers-on-different-ports