rack

10
RACK Sowjanya Mudunuri

Upload: naga-sowjanya-mudunuri

Post on 24-Jun-2015

88 views

Category:

Software


0 download

DESCRIPTION

Rack Intro

TRANSCRIPT

Page 1: Rack

RACK

Sowjanya Mudunuri

Page 2: Rack

RACK

Disclaimer:

This notes is composed from various resources which are listed at the end of this presentation. This presentation is used to help my friends get some basic knowledge about RACK

Page 3: Rack

What is Rack?

Developed by Christian Neukirchen

A modular ruby webserver interface for developing web applications in Ruby

Available as a Ruby Gem

The source code can be found at https://github.com/rack/rack

Page 4: Rack

Rack Application

A Rack Application is a Ruby Object that responds to Call method

It takes one argument the environment hash and returns an array of three elements. (HTTP response code, a hash of headers, the response body, which responds to each)

The Gem provides handlers to connect to all kinds of web servers to rack. Mongrel, Thin, Webrick, Puma …

Page 5: Rack

Basic Rack Appmy_first.rb

require 'rack’

my_app = Proc.new do |env|

["200", {'Content-Type' => 'text/html'}, ["Sowju's First rack app"]]

end

#Starts on port 8080

Rack::Handler::WEBrick.run my_app

Page 6: Rack

Alternative Rack App

require 'rack’

class HelloWorld

def call(env)

[200, {"Content-Type" => "text/html"}, "Hello Rack!"]

end

end

Rack::Handler::Thin.run HelloWorld.new, :Port => 9292

Page 7: Rack

Steps needed to deploy a rack app to Heroku

Create your .rvmrc file with the following contents(Preferred)

rvm_install_on_use_flag=1

rvm_trust_rvmrcs_flag=1

rvm_gemset_create_on_use_flag=1

rvm use ruby-2.1.0@first-rack create

bundle init

Add gem "rack” to the Gemfile

bundle check

bundle install

bundle show rack

Page 8: Rack

Steps needed to deploy a rack app to Heroku

Create a file named config.ru with the following contents(required)

require './my_app'run MyApp.new

MyApp.new is the Rack App

create a heroku app and add the remotes using

git remote add heroku <link_to_the_heroku_app>

git push heroku master

Page 9: Rack

ApplicationsRack Middleware in Sinatra and Rails

Rack::ShowExceptions

Rack::CommonLogger

Rack::UrlMap

Sinatra and Rails ride on top of Rack

Rails.application is the primary Rack application object

Any rack compliant web server should be using Rails.application object to serve a Rails application

Easy to combine web applications(just a ruby object) and run them on a single web server without external configuration