-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Routing priority issue in Grape v2.1.0 when using with rails #2452
Comments
Looks like a regression. Try porting this into a spec in this repo without rails? Then it's easy to bisect down to where it changed. |
I do confirm, this test in our stack is passing in 2.0.0 but not in 2.1.0. There's is something with the context 'rails mounted' do
let(:app) do
require 'rails'
require 'action_controller/railtie'
api = Class.new(Grape::API) do
get('/test_grape'){ 'rails mounted' }
end
Class.new(Rails::Application) do
config.eager_load = true
config.load_defaults 7.1
config.api_only = true
config.consider_all_requests_local = true
config.hosts << 'example.org'
routes.append do
mount api => "/"
get 'up', to: ->(_env) do
['200', {}, ['hello world']]
end
end
end
end
before { app.initialize! }
it 'responds' do
get '/test_grape'
expect(last_response).to be_successful
expect(last_response.body).to eq('rails mounted')
get '/up'
expect(last_response).to be_successful
expect(last_response.body).to eq('hello world')
end
end |
Same problem confirmed. I'm moving the |
Can someone bisect this to a change please? |
@dblock I just did, the test provided by @ericproulx starts failing at |
I found something related to the X-Cascade. I'm still digging |
@eiskrenkov are you using rack >= 3 ? While testing, I found that its only happening with Rack >= 3 but maybe I'm wrong |
@ericproulx yes, it's |
Thank you so much for your work guys @dblock @ericproulx <3 Will try the new version once it's out |
@eiskrenkov please do try HEAD, |
@dblock sure thing! Just tried it in my project, it helped! Routes that are defined under grape mounting are reachable now. Thank you so much for such a quick fix again! |
@dblock Until now, I couldn't wrap my head around this bug because obviously we had a test for cascading. While looking at the Now, when running within a rails app, the |
A test like this one would have catch it context 'cascade within another app' do
subject { last_response.headers }
let(:api) do
Class.new(Grape::API) do
get('/test'){ return_no_content }
end
end
let(:app) do
test_api = api
Rack::Builder.app do
use Rack::Lint
run test_api.new
end
end
before { get '/' }
it { is_expected.to include('x-cascade') }
end
Rack::Lint::LintError:
uppercase character in header name: X-Cascade |
Hello, everyone! When upgrading to grape v2.1.0 we've encountered an issue with routing. I created a sample rails new repo for demo purposes - https://github.com/eiskrenkov/grape-routing-issue-demo
Issue
I'm mounting grape API in rails routes at the top of the file
When i'm doing GET
http://localhost:3000/up
request in grape v2.0.0 it returns response correctly, but in grape v2.1.1 i'm getting 404 error. It seems like something was changed in route prioritising, if nothing matches grape's routes it doesn't continue the journeySteps to reproduce
(export SHOULD_WORK=true; bundle; bundle exec rails s)
will use grape v2.0.0 and will respond to
http://localhost:3000/up
correctly(export SHOULD_WORK=false; bundle; bundle exec rails s)
will use grape v2.1.0 and respond with 404
The text was updated successfully, but these errors were encountered: