Rack

  • Uploaded by: Thomas R. Koll
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Rack as PDF for free.

More details

  • Words: 274
  • Pages: 11
Rack Thomas R. Koll http://ananasblau.com [email protected]

What is Rack? ●

Rack is written in Ruby



Rack is a webserver framework



Rack is between the webserver and your app



Rack can be a webapp, if it's a simple task



Apps can be anything: Rails, Sinatra, merb etc.



Rack is dead simple, even I understood it

Internetto

Webserver Rack

Rails Application

sinatra Application

Specification ●

Rack is an Object



Rack has one method: call



call accepts one parameter: environment



environment is an hash with request info



Call must return an array with: ●

status code (1xx, 2xx, 3xx, 4xx, 5xx)



response headers is a hash with e.g. 'Content-Type'



body is used for the actual output

Example 1: simple server

Or use Rack::Directory

Example 2: root_path per domain ●

Allow customers to point domains to your app



Allow them to set a different root_path. E.g.







/albums/32



/blog/why-this-website-is-no-more

Dispatch subdomains to different controllers ●

/static/jobs for jobs.example.com



/blog for blog.example.com



/dashboard for dashboard.example.com

Could be done by mod_rewrite

DomainDispatcher

Example 3: Rack::Cache ●

Usually separate app/server like squid



In mephisto done via rewrite rules in webserver: ●

Not very flexible



Not very portable friendly



Separated from your app

RewriteCond %{REQUEST_URI} ^/[^.]+$ RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}% {REQUEST_FILENAME}.html -f RewriteRule ^/(.*)$ /cache/%{HTTP_HOST}%{REQUEST_FILENAME}.html [QSA,L] RewriteCond %{REQUEST_URI} ^/.+$ RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}% {REQUEST_FILENAME} -f RewriteRule ^/(.*)$ /cache/%{HTTP_HOST}%{REQUEST_FILENAME} [QSA,L]

Existing middleware There's plenty of stuff other contributed: ●

Rack::Cache



Rack::ETag



Rack::MailExceptions



Rack::Backstage



Rack::Auth::OpenID and Basic



Rack::Static



and many more...

Weblinks ●

http://rack.rubyforge.org



http://github.com/rack/rack-contrib/



http://tomayko.com/src/rack-cache/



http://guides.rubyonrails.org/rails_on_rack



http://railscasts.com/episodes/151-rack-middleware

Related Documents

Rack
June 2020 23
Rack
July 2020 18
Rack
May 2020 17
Chisel Rack
November 2019 37
Rack Map
July 2020 12
Server Rack
June 2020 20

More Documents from ""

May 2020 1
May 2020 1
Rspec
June 2020 0
Rack
May 2020 17
Study In Europe
June 2020 21
May 2020 37