-
-
Notifications
You must be signed in to change notification settings - Fork 97
Open
Description
Hi. I am a bit stuck when trying to use hanami-router with dynamic path segments using scope.
Consider these two examples and the resulting PATH_INFO and SCRIPT_NAME fields in the rack env. For both examples let's look at the request GET /stations/42/trains.
Example A - scope with dynamic segment
# config.ru
Router = Hanami::Router.new do
scope '/stations/:station_id' do
mount ->(env) { binding.irb }, at: '/'
end
end
run Router
# "SCRIPT_NAME" => "/stations/:station_id"
# "PATH_INFO" => "/stations/42/trains",
# Rack::Request.new(env).path # => "/stations/:station_id/stations/42/trains"Example B - scope without dynamic segment
Router = Hanami::Router.new do
scope '/stations' do
mount ->(env) { binding.irb }, at: '/'
end
end
run Router
# # "SCRIPT_NAME" => "/stations"
# # "PATH_INFO" => "/42/trains"
# Rack::Request.new(env).path # => "/stations/42/trains"The issue I have with this is that using a scope with a dynamic segment (Ex A) makes Rack::Request#path unusable. – I think it somehow makes sense that SCRIPT_NAME is actually "/stations/:station_id" here, but it's hard to get the actual request when using Rack::Request#path.
Questions:
- Is this behavior intended?
- My assumption is that you should be able to get to the actual request path by concatenating
SCRIPT_NAME + PATH_INFO- Is that wrong?
Metadata
Metadata
Assignees
Labels
No labels