Skip to content

Instantly share code, notes, and snippets.

@enoliglesias
Last active April 19, 2017 17:56
Show Gist options
  • Save enoliglesias/741f2be43fda418e3a669bcc3e7b9003 to your computer and use it in GitHub Desktop.
Save enoliglesias/741f2be43fda418e3a669bcc3e7b9003 to your computer and use it in GitHub Desktop.
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