Last active
August 17, 2016 15:14
-
-
Save dylanninin/4c41cff6da79ca1a6b8c4126eda2dea2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MiddleWare1 | |
def initialize(app) | |
@app = app | |
end | |
def call env | |
puts self.class | |
status, headers, body = @app.call(env) | |
append_str = "\nGreetings from #{self.class}" | |
body << append_str | |
[status, headers, body] | |
end | |
end | |
class MiddleWare2 | |
def initialize(app) | |
@app = app | |
end | |
def call env | |
puts self.class | |
status, headers, body = @app.call(env) | |
append_str = "\nGreetings from #{self.class}" | |
body << append_str | |
[status, headers, body] | |
end | |
end | |
use Rack::Reloader | |
use MiddleWare1 | |
use MiddleWare2 | |
app = Proc.new {|env| | |
puts "#{Time.now}, env: #{env}" | |
# status_code, headers, body | |
[200, {}, ["Hello. The time is #{Time.now}"]] | |
} | |
run app | |
################################################################################ | |
# request | |
# | | |
# | | |
# | |
# MiddleWare1 | |
# | | |
# | | |
# | |
# MiddleWare2 | |
# | | |
# | | |
# | |
# App | |
# | |
# onion architecture:https://github.com/dylanninin/dylanninin.github.com/issues/4 | |
# - calling: request -> MiddleWare1 -> MiddleWare2 -> App | |
# - returning: App -> MiddleWare2 -> MiddleWare2 --> response | |
################################################################################ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rackup middlewares.ru
curl -v http://127.0.0.1:9292