-
-
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
Path based versioning not recognizing '/' route #86
Comments
Is anyone else bothered about this? Worth a patch? |
@gerhard definitely worth a patch, just haven't found time to fix it. |
@jch will see if I can make some time for this. This is what I'm currently using (as a workaround): # This should have been the default route, but grape requires a fix for this:
# https://github.com/intridea/grape/issues/86
desc 'The current page, showing details about all available routes'
get '/routes' do
API.routes.map { |route| route.instance_variable_get(:@options) }
end |
@gerhard thanks, feel free to ping me if you need any explanation of the code. My fix in the project was to not use a top level route and always scope things underneath a resource name: class API < Grape::API
resources :things do
# routes /things fine
get do
end
end
end |
Hey guys, I'm running into the same issue. After some investigating it seems all to boil down to a mechanism in rack-mount which normalizes the path of each request before matching it against the route set. Anyway, if you do that for a path versioned call you end up with a call to /\A\/(?<version>v1)\/(?:\.(?<format>[^\/.?]+))?\Z/ which then does not match anymore. I suggest just changing the matcher to be like /\A\/(?<version>v1)(\/?:\.(?<format>[^\/.?]+))?\Z/ (notice that the middle This way it will match on the normalized path. Any obligations? If not I will just do so and send you guys a pull request once that is done. Cheers |
@walski great sleuthing! I'd love to see a PR for this, especially if you could have tests for both cases (trailing and non-trailing slash). |
Path based versioning works for all routes whose paths are not the root path '/'
The text was updated successfully, but these errors were encountered: