From Sinatra Base object. Get port of application including the base object

梦想与她 提交于 2019-12-11 11:53:59

问题


I have a Sinatra::Base object that I would like to include in all of my web apps. In that base class I have the configure method which is called on start-up.

I would like that configure code to 'register' that service with a centralized database. The information that needs to be sent when registering is the information on how to contact this web-service... things like host and port.

I then plan on having a monitoring service that will spin over all registered services and occasionally ping them to make sure they are still up and running.

In the configure method I am having trouble getting the port information. The 'self.settings.port' variable doesn't seem to work in this method.

a) any ideas on how to get the port? I have the host.

b) is there a sinatra plug-in that already does something like this so I don't have to write it myself? :-)

//in my Sinatra::Base code. lets call it register_me.rb

RegisterMe < Sinatra::Base

configure do

//save host and port information to database

end

get '/check_status'

//return status

end


//in my web service code

require register_me //at this point, sinatra will initialize the RegisterMe object and call configure

post ('/blah')

//example of a method for this particular web service

end


回答1:


Sinatra::Application.port will return the correct port



来源:https://stackoverflow.com/questions/2932750/from-sinatra-base-object-get-port-of-application-including-the-base-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!