Skip to content

Instantly share code, notes, and snippets.

@enoliglesias
Last active April 19, 2017 17:56
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
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