From Sinatra Base object. Get port of application including the base object
Posted
by Poul
on Stack Overflow
See other posts from Stack Overflow
or by Poul
Published on 2010-05-28T21:50:06Z
Indexed on
2010/05/28
21:52 UTC
Read the original article
Hit count: 257
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
© Stack Overflow or respective owner