Base de todo ruby web framework
[status_code, {headers}, [body]]
require "rack"
require "thin"
class HelloWorld
def call(env)
[ 200, { "Content-Type" => "text/plain" }, ["Hello World"] ]
end
end
Rack::Handler::Thin.run HelloWorld.new
require "rack"
require "thin"
app = -> (env) do
[ 200, { "Content-Type" => "text/plain" }, env ]
end
Rack::Handler::Thin.run app
require 'rack'
@app = MyApp.new
Rack::Handler::Puma.run(@app)
Text
Text
require "rack"
require "thin"
app = -> (env) do
sleep 3
[ 200, { "Content-Type" => "text/plain" }, ["Hello World\n"] ]
end
class LoggingMiddleware
def initialize(app)
@app = app
end
def call(env)
before = Time.now.to_i
status, headers, body = @app.call(env)
after = Time.now.to_i
log_message = "App took #{after - before} seconds."
[status, headers, body << log_message]
end
end
Rack::Handler::Thin.run LoggingMiddleware.new(app)
app =
Rack::Builder.new do |builder|
builder.use FilterLocalHost
builder.run RackApp.new
end
Rack::Handler::Thin app
Rack::URLMap, to route to multiple applications inside the same process.
Rack::CommonLogger, for creating Apache-style logfiles.
Rack::ShowException, for catching unhandled exceptions and presenting them in a nice and helpful way with clickable backtrace.
Rack::File, for serving static files.