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

Infinite redirect loop when trying to access not existing api endpoint #8953

Closed
artplan1 opened this issue Aug 28, 2018 · 1 comment
Closed

Comments

@artplan1
Copy link
Contributor

Context

Requesting not existing api route causes infinite redirect loop

Expected Behavior

Return 404?

Actual Behavior

Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
13:34:15 web.1        | Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
13:34:15 web.1        | Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
13:34:15 web.1        | Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
13:34:15 web.1        | Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
13:34:15 web.1        | Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
13:34:15 web.1        | Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
13:34:15 web.1        | Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
13:34:15 web.1        | Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
13:34:15 web.1        | Started GET "/api/v1/v.json" for 127.0.0.1 at 2018-08-28 13:34:15 +0300
...

Possible Fix

It's caused by 2 last route matches in api routes config. Maybe check for format in path can help

https://github.com/spree/spree/blob/master/api/config/routes.rb#L145

match 'v:api/*path', to: redirect { |params, request|
      format = ".#{params[:format]}" unless params[:format].blank?
      query  = "?#{request.query_string}" unless request.query_string.blank?

      "#{spree_path}api/v1/#{params[:path]}#{format}#{query}"
    }, via: [:get, :post, :put, :patch, :delete]

Steps to Reproduce

  1. Send to request to any not existing api endpoint
  2. ERR_TOO_MANY_REDIRECTS

Sample spec (storefront/products does not exist in api v1)

it 'returns 404' do
  visit '/api/v1/storefront/products'
  expect(response.status).to eq 404
end
Failures:

  1) API V1 api request when route does not exist returns 404
     Failure/Error: visit '/api/v1/storefront/products'

     Capybara::InfiniteRedirectError:
       redirected more than 5 times, check for infinite redirects.

Your Environment

spree master

@damianlegawiec
Copy link
Member

Hey @artplan1 this was fixed via #8976 , you can update spree to 3.7.0.beta

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