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

Mounting the engine with a route constraint #92

Open
olimart opened this issue Mar 7, 2024 · 2 comments
Open

Mounting the engine with a route constraint #92

olimart opened this issue Mar 7, 2024 · 2 comments

Comments

@olimart
Copy link

olimart commented Mar 7, 2024

Hey,

Albeit the mention of setting the base controller, I was trying to define a contraint while mounting the engine.
mount MissionControl::Jobs::Engine, at: "jobs", constraints: AdminConstraint.new

class AdminConstraint
  def matches?(request)
    return unless request.session[:user_id]
    User.find(request.session[:user_id])&.admin?
  end
end

which fails because <ActionDispatch::Request::Session:0x72ba0 not yet loaded>

I don't know if it's a limit of Rails engine (it used to work with Sidekiq dashboard though) or if there is some loading logic to change to make it work. Is that something that can be envisioned? Thanks

@gjtorikian
Copy link

Unsure if this'll be helpful in your situation, but for a constraint I write mine as:

  constraints ->(request) { StaffController.staff_request?(request) } do
    mount MissionControl::Jobs::Engine, at: "staff/jobs"
  end  

@dlinch
Copy link

dlinch commented Nov 5, 2024

I came here looking for a response to this. Sidekiq has a really nice use method that allows you to drop in middleware. It would be helpful for attaching the Rack Basic Auth in case I'm in charge of debugging a site I don't have an account for. It looks like:

Sidekiq::Web.use Rack::Auth::Basic do |username, password|
    username == 'some_user' && password == 'some_password'
end
mount Sidekiq::Web => '/sidekiq'

Where the username and password are likely stored in the ENV or credentials.

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

3 participants