Questions tagged [rack]

Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.

Rack is a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.

Useful Links

1617 questions
19
votes
2 answers

How do I use a Rack middleware only for certain paths?

I'd like to have MyMiddleware run in my Rack app, but only for certain paths. I was hoping to use Rack::Builder or at least Rack::URLMap, but I can't quite figure out how. This is what I thought would work, but doesn't: # in my rackup file or Rails…
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
19
votes
5 answers

Ruby Rack - mounting a simple web server that reads index.html as default

I'm trying to get some information from this tutorial: http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder basically I want to have a file config.ru that tell rack to read the current directory so I can access all the files just like a simple…
zanona
  • 12,345
  • 25
  • 86
  • 141
18
votes
1 answer

Rails 3 middleware modify request headers

My setup: Rails 3.0.9, Ruby 1.9.2 I am working on my first middleware app and it seems like all of the examples deal with modify the response. I need to examine and modify the request headers in particular, delete some offending headers that cause a…
Bob
  • 8,424
  • 17
  • 72
  • 110
18
votes
5 answers

open-source mini-heroku?

I started playing with Sinatra and deploying on Heroku, which I find really enjoyable. I don't need the scalability Heroku provides, but I really like their CLI and the ability to deploy an app with a simple push. Is there an open source project…
Rom1
  • 3,167
  • 2
  • 22
  • 39
17
votes
2 answers

Making Rails tests aware of Rack middleware outside Rails's internal chain

Context: an application uses a piece of Rack middleware that must be setup in config.ru, rather than Rails's internal Middleware chain. This is for reasons not relevant to this question. Question: how do I make my tests (functional and integration)…
pablobm
  • 2,026
  • 2
  • 20
  • 30
17
votes
1 answer

Websocket header missing

I'm using the 'faye' gem with Rails 3.2.13. In development I'm running faye on localhost:9292 and my app on localhost:3000. I'm able to activate pop-up windows with a curl request from the command line but I can't establish a connection from within…
DizzyDez
  • 215
  • 3
  • 7
17
votes
3 answers

Disable Sprockets asset caching in development

I'm using Rails 3.2.13 and the Rails Asset Pipeline. I want to use the Asset Pipeline so I can use SASS and CoffeeScript and ERB for my assets and have the Pipeline automatically compile them, so I cannot turn off the pipeline in development. I am…
Old Pro
  • 24,624
  • 7
  • 58
  • 106
17
votes
5 answers

Sinatra and Rack Protection setting

I am using Sinatra and CORS to accept a file upload on domain A (hefty.burger.com). Domain B (fizzbuzz.com) has a form that uploads a file to a route on A. I have an options route and a post route, both named '/uploader'. options '/uploader' do …
David Lazar
  • 10,865
  • 3
  • 25
  • 38
16
votes
4 answers

mongoid query caching

Rails' ActiveRecord has a feature called Query Caching (ActiveRecord::QueryCache) which saves the result of SQL query for the life-span of a request. While I'm not very familiar with the internals of the implementation, I think that it saves the…
Roman
  • 13,100
  • 2
  • 47
  • 63
16
votes
6 answers

Single Sign-On Server Authentication in Ruby/Rack

I write and host web applications on Windows servers for intranet usage. My server stack uses Sinatra (which uses Rack), Thin, and (in some cases) Apache for reverse-proxying only. I want to support Single Sign-on (using NTLM or Kerberos) within our…
Phrogz
  • 296,393
  • 112
  • 651
  • 745
16
votes
3 answers

Redirect logger output for a specific controller in Rails 4

I've built a solution based on the answer in my previous question Redirect logger output for a specific controller in Rails 3 for Rails 3. It works great however now I am trying to apply the same middleware based solution to a Rails 4 project but…
Streamline
  • 2,040
  • 4
  • 37
  • 56
16
votes
1 answer

Alter Rails params hash from Rack middleware

I am attempting to add a value to the Rails params hash from a custom Rack middleware object. My current approach is using class PortalResolver def initialize(app) @app = app end def call(env) begin url =…
silatham99
  • 285
  • 3
  • 8
16
votes
1 answer

How do I specify Origin Whitelist Options in Sinatra using Rack/Protection

I have a web app, lets say http://web.example.com making a POST request to http://api.example.com. The api server is running the latest version of Sinatra with rack protection enabled. I am getting this error 'attack prevented by…
kelsmj
  • 1,183
  • 11
  • 18
16
votes
3 answers

Trigger Rack middleware on specific Rails routes

Is it possible to trigger Rack middleware only on specific Rails routes? For example, let's say I wanted to run a rate limiter middleware only on the api namespace. namespace :api do resources :users end
Cev
  • 1,388
  • 1
  • 13
  • 18
15
votes
3 answers

Where to insert Rack::Deflater in the rack?

I currently have the following: use Rack::Rewrite use Rack::Cache, {:verbose=>true, :metastore=>"memcached://localhost:11211/rack-cache/meta", :entitystore=>"memcached://localhost:11211/rack-cache/body"} use Rack::Rewrite use Rack::Lock use…
Binary Logic
  • 2,562
  • 7
  • 31
  • 39