A minimal Rack app to lookup your external IP address
I think I first heard the term “Rack-app” when I started using Heroku to host a couple of projects. I didn’t know an awful lot about Rack but I did know that it helped a great deal when it came to getting my Rails and Sinatra apps off my workstation and onto the web.
Tonight I thought I’d have another quick look at how it works, what it takes to build a Rack-app and what information about the request is available to the handler.
The result was the following, an object which responds to call and returns a HTTP response code, headers and a body:
ip = lambda do |env| [200, {“Content-Type” => “text/plain”}, [env[“REMOTE_ADDR”]]] end
run ip
I have this running on ip.stevenwilkin.com and it provides the same useful function as whatismyip.com but without the ads :)
The code is available on GitHub as always.