Skip to content

Instantly share code, notes, and snippets.

@udzura
Last active October 22, 2020 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udzura/33f4865bd3d0c88d866a08fdff18826e to your computer and use it in GitHub Desktop.
Save udzura/33f4865bd3d0c88d866a08fdff18826e to your computer and use it in GitHub Desktop.
source "https://rubygems.org"
gem "rack"
gem "sinatra"
# gem "pry"
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
$ 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