如何找到运行 rails 实例的本地端口? [英] How to find the local port a rails instance is running on?

查看:23
本文介绍了如何找到运行 rails 实例的本地端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我希望我的 Rails 应用程序实例能够在我正在玩的I'm up"类型的事情上注册自己,并且我希望它能够提及它正在运行的本地端口.我似乎不知道怎么做 - 事实上,只是找出它的 IP 很棘手,需要一点点破解.

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 running on. I can't seem to find how to do it - in fact just finding out its IP is tricky and needs a bit of a hack.

但没问题,我有 IP - 但是我如何找到我的 mongrel/thin/webrick 服务器运行的端口?

But no problem, I have the IP - but how can I find what port my mongrel/thin/webrick server is running on?

更明确地说,如果我使用 script/server -p 3001 启动一个 rails 应用程序,我该怎么做才能将 3001 拉入应用程序中.

To be super explicit, if I start a rails app using script/server -p 3001, what can I do to pull that 3001 inside the app.

推荐答案

您可以调用 Rails::Server.new.options[:Port] 来获取运行 Rails 服务器的端口.这将从您的 rails server 命令解析 -p 3001 参数,或默认为端口 3000.

You can call Rails::Server.new.options[:Port] to get the port that your Rails server is running on. This will parse the -p 3001 args from your rails server command, or default to port 3000.

这篇关于如何找到运行 rails 实例的本地端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆