Skip to content

Add middleware from the outside #2169

Open
@thedarkside

Description

@thedarkside

Hey everyone!

Currently iam working on a custom Railtie which wants to add a middleware to all mounted Grape::APIs in a Rails project in the Railties after_initialize block.
My first naive try was MyAPI.send(:insert_after, Rack::Head, MyMiddleware). It doesnt fail and MyAPI.middleware lists MyMiddleware but its not being called when requests come in. It just doesnt work.
So my understanding is that the mounted API is being instantiated before my addition runs and the change is not being picked up by the API.
Ive also experimented with MyAPI.compile! to kind of force a reload of the Grape API. This didnt succeed either. I have also realized that the instantiation process is not that easy to understand! Its quite complex.

What am i missing here?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions