Created
January 4, 2016 07:19
-
-
Save telent/ef0bdee073d8f4e4dab5 to your computer and use it in GitHub Desktop.
puma on random port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack' | |
require 'puma' | |
def my_app | |
return ->(env) { | |
[200, {"content-type"=>"text/plain"}, | |
["hello world"]] | |
} | |
end | |
_,_,_,my_address = UDPSocket.new.tap {|u| u.connect("8.8.8.8", 53) }.addr | |
puma = Rack::Handler.get("puma") | |
puma.run(my_app, {Host: "0.0.0.0", Port: 0}) do |s| | |
# oh Demeter ... | |
realport = s.binder.ios.first.local_address.ip_port | |
FileUtils.mkdir_p("run") | |
File.open("run/local_address", "w") do |f| | |
local_endpoint="#{my_address}:#{realport}" | |
f.write("#{local_endpoint}\n") | |
$stderr.write("Wrote #{local_endpoint.inspect} to run/local_address\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment