Created
December 20, 2017 15:51
-
-
Save WyattJia/93c12baad6e2bad0e3a2287620e65a08 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
#! /usr/bin/env ruby | |
# encoding: utf-8 | |
require 'rack' | |
class MyMiddleware | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
code, headers, body = @app.call(env) | |
body << 'this is my middleware' | |
[code, headers, body] | |
end | |
end | |
class MyApp | |
def call(env) | |
[200, {'Content-Type' => 'text/plain'}, ['hello world']] | |
end | |
end | |
app = Rack::Builder.app do | |
map '/' do | |
run MyApp.new | |
end | |
map '/middleware' do | |
use MyMiddleware | |
run MyApp.new | |
end | |
end | |
run app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment