small medium large xlarge

31 Jan 2009, 12:40
James Frost (3 posts)


I loved the screencast, and Sinatra looks fantastic. However, I had a slight issue once I’d deployed my app to my server. The hashed URL it gives me is like:

Which obviously, isn’t correct - would you have any idea why this uses that IP and the development port number? I’m serving the app up with passenger now, with a proper domain name. Is there a configuration option I’ve missed somewhere? Or something missing in the code?

Any help would be greatly appreciated! :)


31 Jan 2009, 13:08
James Frost (3 posts)

Just did a little more investigating, and it seems like is returning and Sinatra::Application.port is returning 4567, even when deployed.

I can’t work out why!

01 Feb 2009, 23:26
Adam Keys (4 posts)

Nice find, James.

Sinatra is falling back to its defaults here. So, you could pass options to your Sinatra app to override or @Sinatra::Application.port@. Or, you could bypass @base_url@ and send only relative URLs. The one place you’d want to use an absolute URL is in your handler that redirects the user to the destination site. I’d favor the latter approach.

Make sense?

02 Feb 2009, 15:37
James Frost (3 posts)

Thanks for that, Adam. Your suggestions do make sense, but how would you do the latter and have the contents of the textarea on the info page of a URL contain the correct URL?

03 Feb 2009, 14:52
Adam Keys (4 posts)

Good point, James. Rack’s request object provides a @host@ method like this:

    def host
      # Remove port number.
      (@env["HTTP_HOST"] || @env["SERVER_NAME"]).gsub(/:\d+\z/, '')

Depending on how you’re running your app (Passsenger, Mongrel, Thin, etc.), that may give you the info you need to generate an absolute URL.

You could also set an environment variable for your server. You’d want to do this in the command that starts it if you’re using Mongrel, Thin, etc. or in your Apache config if you’re using Passenger.

Finally, you could set a constant in your configure block. Like so:

configures :production do
  HOST = ''
  PORT = 80
You must be logged in to comment