Skip to content

Instantly share code, notes, and snippets.

@hiboma
Created June 18, 2012 16:12
Show Gist options
  • Save hiboma/2949154 to your computer and use it in GitHub Desktop.
Save hiboma/2949154 to your computer and use it in GitHub Desktop.
sinatra - return requested port (SERVER_PORT)
#!/usr/bin/env ruby
require 'sinatra'
get '/' do
sprintf "%d\n", request.port
end
@hiboma
Copy link
Author

hiboma commented Jun 18, 2012


$ bundle exec ruby test.rb
[2012-06-19 01:12:57] INFO  WEBrick 1.3.1
[2012-06-19 01:12:57] INFO  ruby 1.9.3 (2011-10-30) [x86_64-darwin10.8.0]
== Sinatra/1.3.2 has taken the stage on 4567 for development with backup from WEBrick
[2012-06-19 01:12:57] INFO  WEBrick::HTTPServer#start: pid=49564 port=4567
localhost - - [19/Jun/2012:01:13:00 JST] "GET / HTTP/1.1" 200 5
- -> /
localhost - - [19/Jun/2012:01:13:04 JST] "GET / HTTP/1.1" 200 3
- -> /

Now sinatra.rb is listeing on port 4567

@hiboma
Copy link
Author

hiboma commented Jun 18, 2012

$ curl http://127.0.0.1:4567/
4567
$ curl -H'Host: example.com' http://127.0.0.1:4567/
80
$ curl -H'Host: example.com:4567' http://127.0.0.1:4567/
4567

it seems to be wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment