Rack provides a minimal, modular, and adaptable interface for developing web applications in Ruby.
Questions tagged [rack-middleware]
66 questions
1
vote
1 answer
How do I disable middleware in Sinatra?
I'm making a secured web service using Sinatra. It requires SSL and a security token sent with every request. Therefore I've made a simple middleware that checks each incoming request for a security token, and denies the request if it's missing or…

Hubro
- 56,214
- 69
- 228
- 381
1
vote
1 answer
Rack middleware global middleware
Can someone please explain how this peace of code works, especially the log filter part.
I want to assign log_attributes_filter from the rack file, where i calling use MongodbLogger::RackMiddleware, how to do so?
# Rack middleware for mounted rack…

Petya petrov
- 2,153
- 5
- 23
- 35
1
vote
2 answers
How to access rails cache inside rack middlware
I have some custom middleware that is include at the top of my stack and what i need to do in it is access the rails cache. How can I load/access the rails cache from the middleware without having to load the whole rails app up first?

Jake McAllister
- 1,037
- 3
- 12
- 29
1
vote
1 answer
How to use Rack middleware to simultaneously set cookie and send response with cookie in effect
I'm trying to use Rack Middleware to set a cookie and send a response with the cookie in effect in the same request-response cycle.
Here is the context: I'm working on a website with two modes: a US mode and a UK mode (different logos, navigation…

User314159
- 7,733
- 9
- 39
- 63
1
vote
1 answer
rewrite non www to www except subdomain rails 3 and rack
I need to be able to rewrite non www to www but NOT in the case when there is a (non www) subdomain present.
so example.com to-> www.example.com
but sub.example.com remains sub.example.com
I'm in rails 3 and it seems this should be accomplished…

cman77
- 1,753
- 1
- 22
- 48
0
votes
1 answer
Sinatra rack middleware hijacks '/' root url
I'm trying to use a Sinatra app as middleware in my Rails app.
I've tested a basic Sinatra app in the /lib folder of the Rails app, used the middleware and set a route. That worked fine.
What I want to be able to do is extract the Sinatra app and…

ghr
- 647
- 4
- 16
0
votes
1 answer
Rack middleware - what header is added?
In my Rails 7 app I want to implement Idempotency for incoming requests. I reckon this is a good example to use Rack middleware for such an action. So the implementation is simple:
class IdempotencyMiddleware
def initialize(app)
@app =…

mr_muscle
- 2,536
- 18
- 61
0
votes
0 answers
Rails ExceptionNotifier -> Notifier based on title
Is it possible to change ExceptionNotifier exception_recipients based on some variable or maybe Exception title?
I want to send some main notifies to one email and other created via ExceptionNotifier.notify_exception to another.

Michał Zubrzycki
- 845
- 3
- 11
- 20
0
votes
0 answers
How to build post params from json object with rack middleware on rails
I receive a json object encoded with jwt, in the middleware i want to build post params after decode the message
params = JSON.parse(env['rack.input'].read)
json_decoded = decode_data(params['data'], secret_key)
puts "DECODED:…
0
votes
0 answers
Add middleware to Devise failure app
After a failed login Devise seems to be calling the failure app in a new rack env and returning it's response which is typically the login page.
How do I add a middleware to devise failure app?

Favourite Onwuemene
- 4,247
- 8
- 28
- 46
0
votes
1 answer
Passing multiple arguments to Rack middleware in Rails application.rb
I am creating a Rack Middleware which I want to use in my Rails App. Basically, I need to log requests matching particular urls to my Database. In order to do this I need to pass database configuration to my Middleware so it can establish connection…

abhinav
- 607
- 6
- 18
0
votes
1 answer
Rails I18n routes with middleware
I need to translate my site and I'm using I18n for this purpose.
Using locale as URL param, I want to redirect users to their locale, which saved in their cookies.
Here is string from routes.rb which I'm using to redirect:
get "/path", to:…

rado
- 111
- 1
- 3
- 12
0
votes
2 answers
Rack::ShowExceptions enabled in production Rails 4.0.4
Running into a odd issue where Rack::ShowExceptions is rendering detailed exceptions for my rails 4.0.4 app in the production environment. Adding a config.middleware.delete(Rack::ShowExceptions) to config/application.rb still managed to result in…

dleve123
- 100
- 7
0
votes
1 answer
Using Rack::Attack to throttle Basic Auth
I have gem rack-attack setup for my app. I want to start throttling basic auth authentication based on IP.
My basic auth code setup like so:
# config/environments/production.rb
config.middleware.insert_after(::Rack::Lock, '::Rack::Auth::Basic',…

Jonathan Mui
- 2,471
- 3
- 19
- 27
0
votes
1 answer
rack doesn't identified as a command in rails4
I have a rails4 project gem 'rails', '4.0.2', and I have created a custom rack module in
config/initializers/request_timer.rb, from Ryan bates screencast
but when I run the command rack middleware, inside my project, it says
-bash: rack: command…

sameera207
- 16,547
- 19
- 87
- 152