Ruby Sinatra Webservice running on localhost:4567 but not on IP
When using the built-in server through the run! if app_file == $0
check, Sinatra's doc explains that set :bind, '0.0.0.0'
is required to make the interface available outside the localhost
layer.
It is not required to use a custom IP address or a reverse DNS (mydomain.com…): '0.0.0.0'
is the legit value expected by Sinatra, which will be interpreted correctly.
Therefore, a minimal, self-contained Sinatra application made available on all interfaces, not only localhost
, would be:
require 'sinatra/base'class MyApp < Sinatra::Base set :bind, '0.0.0.0' get '/' do 'Hello World' end run! if app_file == $0end