Skip to content

Conversation

@timriley
Copy link
Member

@timriley timriley commented Dec 12, 2025

Allow PATH_INFO to remain an empty string when a request is made for the exact prefix name of a mount, e.g. a request to "/settings" for this route:

mount ->(env) { [200, {}, [env["PATH_INFO"]] }, at: "/settings"

This ensures that the Rack environment can be used to reconstruct the same path as used for the original request (e.g. "/settings" instead of "/settings/" for the example above).

To ensure compatibility for routers used within mounts, consider an empty string to be equivalent to "/" for the purposes of route matching.

This allows a router to be mounted and have it root route be used when a request is made to the exact mount prefix without any trailing slash:

mounted_router = Hanami::Router.new do
  root to: ->(env) { [200, {}, ["Hello from root"]] }
end

mount mounted_router, at: "/settings"

In the above example, a request to /settings will still serve the route returning "Hello from root".

I believe that this compatibility should allow us to push this out as a patch release rather than wait for a bigger release.

Fixes #290

@timriley timriley requested review from a team, dcr8898 and kyleplump December 12, 2025 05:58
@timriley timriley force-pushed the fix-root-path-info-for-mounts branch from d8bfc46 to 9113f96 Compare December 12, 2025 05:59
Allow PATH_INFO to remain an empty string when a request is made for the exact prefix name of a mount, e.g. a request to "/settings" for this route:

```
mount ->(env) { [200, {}, [env["PATH_INFO"]] }, at: "/settings"
```

This ensures that the Rack environment can be used to reconstruct the same path as used for the original request (e.g. "/settings" instead of "/settings/" for the example above).

To ensure compatibility for routers used within mounts, consider an empty string to be equivalent to "/" for the purposes of route matching.

This allows a router to be mounted and have it root route be used when a request is made to the exact mount prefix without any trailing slash:

```
mounted_router = Hanami::Router.new do
  root to: ->(env) { [200, {}, ["Hello from root"]] }
end

mount mounted_router, at: "/settings"
```

In the above example, a request to /settings will still serve the route returning "Hello from root".
@timriley timriley force-pushed the fix-root-path-info-for-mounts branch from 9113f96 to 807e3d1 Compare December 16, 2025 22:24
@timriley timriley merged commit 6542feb into main Dec 16, 2025
18 checks passed
@timriley timriley deleted the fix-root-path-info-for-mounts branch December 16, 2025 22:28
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

Successfully merging this pull request may close these issues.

Using mount adds trailing slash

3 participants