How to find the local port a rails instance is running on?

前端 未结 6 558
滥情空心
滥情空心 2020-11-30 12:23

So I would like my Rails app instances to register themselves on a \"I\'m up\" kind of thing I\'m playing with, and I\'d like it to be able to mention what local port it\'s

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 12:53

    For Rails 5.1 development server.

    if Rack::Server.new.options[:Port] != 9292 # rals s -p PORT
      local_port = Rack::Server.new.options[:Port]
    else
      local_port = (ENV['PORT'] || '3000').to_i # ENV['PORT'] for foreman
    end
    

提交回复
热议问题