Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on how to Add Middleware (V4) #150

Closed
Landon-Alo opened this issue Mar 4, 2023 · 2 comments
Closed

Documentation on how to Add Middleware (V4) #150

Landon-Alo opened this issue Mar 4, 2023 · 2 comments

Comments

@Landon-Alo
Copy link

Hello! I was wondering how to add middleware under the new V4 paradigm. Specifically, I'm trying to migrate a Ruby on Rails application that uses the omniauth-auth0 gem. V4 lamby worked great to get up and running but I am hitting a wall now with auth and I believe it is because I need to add the middleware to the handler.

Any tips or documentation for adding middleware in V4? Thank you.

@metaskills
Copy link
Member

Interesting. There are some advanced configs I called out needing documentation in the #138 issue. Normally Rails has lots of middlewares. None of these require the handler to have any knowledge since they all work with Rack (your Rails app) simply by running the application. For example, ActiveRecord's database/shard middlewares. They get wrapped up as part of the application booting via all your standard configurations, gems, etc. I'd be surprised that Omniauth Auth0 was not the same.

That said, there is a configuration to customize the Rack application that the (also configurable) handler sends events to. You can see the default here. https://github.com/customink/lamby/blob/master/lib/lamby/config.rb#L34-L36. I think one valid use case would be doing thing you might normally do in a config.ru file. So to configure the "rack_app" you could add a config/initializers/lamby.rb file with something like this:

Lamby.config.rack_app = Rack::Builder.new do
  map ENV['RAILS_RELATIVE_URL_ROOT'] do
    run Rails.application
  end
end.to_app

@Landon-Alo
Copy link
Author

Landon-Alo commented Mar 6, 2023

Thanks @metaskills for the quick response. This has helped me rule out any weirdness with the handler. I have some new clues to go on and will keep looking. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants