Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Some examples for my "Rack basics" slides :)
class Wadus
def call(env)
['200', {'X-Wadus' => 'Foo'}, ['Rack app with config.ru file']]
end
end
run Wadus.new
class LoggerMiddleware
def initialize(app)
@app = app
end
def call(env)
before = Time.now.to_f
status, headers, body = @app.call(env)
after = Time.now.to_f
puts "[LOGGER] Request time: #{after - before} sec."
[status, headers, body]
end
end
require 'rack'
class Wadus
def call(env)
['200', {'X-Wadus' => 'Foo'}, ['Class based so simple rack app']]
end
end
Rack::Handler::WEBrick.run Wadus.new
require 'rack'
app = -> (env) do
['200', {'X-Wadus' => 'foo'}, ['Proc based so simple rack app']]
end
Rack::Handler::WEBrick.run app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment