api icon indicating copy to clipboard operation
api copied to clipboard

Rack middleware is not called when using scope with interpolation

Open ahx opened this issue 4 years ago • 0 comments

Scenario

There seems to be a problem when adding a middleware inside a scope block with interpolation. Here is an example:

scope 'i' do
  scope ':tenant_id' do
    use LogTenantIdMiddleware

    get 'foo' do
      "Hello, world #{params[:tenant_id]}"
     end
  end
end

Problem

GET "/i/42/foo"

  • LogTenantIdMiddleware is not called
  • Responds with status 200, "Hello, world 42"

GET "/i/:tenant_id/foo"

  • LogTenantIdMiddleware is called
  • Responds with status 200, "Hello, world :tenant_id"

Example

Here is a gist with a demo app to illustrate the issue.

ahx avatar Oct 01 '21 11:10 ahx