Last active
October 22, 2020 09:18
-
-
Save udzura/33f4865bd3d0c88d866a08fdff18826e 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
source "https://rubygems.org" | |
gem "rack" | |
gem "sinatra" | |
# gem "pry" |
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
require "sinatra" | |
require "rack" | |
module RackyRack | |
class Middleware | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
response = Rack::Response[*@app.call(env)] | |
# response.body は配列です | |
# ここでいろいろ加工したり、代入しなおして試してみよう | |
response.body = response.body.map(&:reverse) | |
response.finish | |
end | |
end | |
end | |
get "/" do | |
"This is sample application!!" | |
end | |
use RackyRack::Middleware | |
# Usage: bundle exec ruby racky-app.rb |
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
$ bundle exec ruby racky-app.rb | |
Ignoring curses-1.3.2 because its extensions are not built. Try: gem pristine curses --version 1.3.2 | |
[2020-10-22 18:14:50] INFO WEBrick 1.6.0 | |
[2020-10-22 18:14:50] INFO ruby 2.7.1 (2020-03-31) [x86_64-darwin19] | |
== Sinatra (v2.1.0) has taken the stage on 4567 for development with backup from WEBrick | |
[2020-10-22 18:14:50] INFO WEBrick::HTTPServer#start: pid=33267 port=4567 | |
127.0.0.1 - - [22/Oct/2020:18:14:54 +0900] "GET / HTTP/1.1" 200 28 0.0066 | |
127.0.0.1 - - [22/Oct/2020:18:14:54 JST] "GET / HTTP/1.1" 200 28 | |
- -> / | |
^C== Sinatra has ended his set (crowd applauds) | |
[2020-10-22 18:14:57] INFO going to shutdown ... | |
[2020-10-22 18:14:57] INFO WEBrick::HTTPServer#start done. | |
---- | |
$ curl localhost:4567 | |
!!noitacilppa elpmas si sihT | |
#=> ??? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment