u16suzuの blog

日々学んだことのメモブログです。

素のRackを使ってみる

  • simpleapp.rb
class Hoge
    def call(env)
        [200,
            {"Content-Type" => "text/plain"},
            ["Hello, world!"]
        ]
    end
end
  • simpleapp.ru
require './simpleapp'

run Hoge.new
  • 起動すると Rails でおなじみの WEBrickが起動する. ポート番号は 9292
$ gem install rack
$ rackup simpleapp.ru
[2014-07-22 01:32:54] INFO  WEBrick 1.3.1
[2014-07-22 01:32:54] INFO  ruby 2.1.1 (2014-02-24) [x86_64-darwin13.0]
[2014-07-22 01:32:54] INFO  WEBrick::HTTPServer#start: pid=6449 port=9292
127.0.0.1 - - [22/Jul/2014 01:33:28] "GET / HTTP/1.1" 200 - 0.0011
127.0.0.1 - - [22/Jul/2014 01:33:29] "GET /favicon.ico HTTP/1.1" 200 - 0.0018
  • 表示結果

f:id:u16s:20140722014036p:plain