You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
app.mount() removes the subpath, and this is causing some issues in the inner mounted router.
I think the current behavior works for almost all applications, and in my opinion it should continue to be the default behavior, but in some particular routers, like itty-router-openapi that auto generates some routes for users, is causing some routes to point to non-existing routes.
This issue was raised in itty-router-openapi repo here and the linked issue provides some more information on this.
This example uses itty-router-openapi, but it would work the same way in other routers
Before this issue was raised in itty-router-openapi repository, i wasn't aware of this request.url change from Hono, so my expected behavior before knowing this, would be that a user would just define the base parameter in itty-router-openapi and everything would work correctly, like this example
In this example, calling http://localhost:8787/api/example would print http://localhost:8787/api/example.
What do you see instead?
Running the script in the "What steps can reproduce the bug", then calling http://localhost:8787/api/example prints http://localhost:8787/example.
An example of the auto generated routes not working is to open this url http://localhost:8787/api/docs in the browser, that is trowing an error, because the lib expects the openapi spec to be an /openapi.json but it actually is in /api/openapi.json because of the url re-write.
Additional information
I think that this should continue to be the default way of mounting other routers in Hono, as probably some routers don't support defining base paths and makes the developer experience better for users.
My initial suggestion was to add a parameter when calling the inner router in this line, and this would make "it work" for users, and users wouldn't need to change anything, then on itty-router-openapi side I could expect this new parameter and work around it.
But after talking to @yusukebe he suggested creating an additional option to disable this behavior, maybe something like this app.mount('/api', router.handle, { subpathRewrite: false })
The text was updated successfully, but these errors were encountered:
What version of Hono are you using?
4.3.11
What runtime/platform is your app running on?
Cloudflare workers
What steps can reproduce the bug?
app.mount()
removes the subpath, and this is causing some issues in the inner mounted router.I think the current behavior works for almost all applications, and in my opinion it should continue to be the default behavior, but in some particular routers, like
itty-router-openapi
that auto generates some routes for users, is causing some routes to point to non-existing routes.This issue was raised in itty-router-openapi repo here and the linked issue provides some more information on this.
This example uses itty-router-openapi, but it would work the same way in other routers
What is the expected behavior?
Before this issue was raised in itty-router-openapi repository, i wasn't aware of this
request.url
change from Hono, so my expected behavior before knowing this, would be that a user would just define thebase
parameter in itty-router-openapi and everything would work correctly, like this exampleIn this example, calling
http://localhost:8787/api/example
would printhttp://localhost:8787/api/example
.What do you see instead?
Running the script in the "What steps can reproduce the bug", then calling
http://localhost:8787/api/example
printshttp://localhost:8787/example
.An example of the auto generated routes not working is to open this url
http://localhost:8787/api/docs
in the browser, that is trowing an error, because the lib expects the openapi spec to be an/openapi.json
but it actually is in/api/openapi.json
because of the url re-write.Additional information
I think that this should continue to be the default way of mounting other routers in Hono, as probably some routers don't support defining base paths and makes the developer experience better for users.
My initial suggestion was to add a parameter when calling the inner router in this line, and this would make "it work" for users, and users wouldn't need to change anything, then on itty-router-openapi side I could expect this new parameter and work around it.
But after talking to @yusukebe he suggested creating an additional option to disable this behavior, maybe something like this
app.mount('/api', router.handle, { subpathRewrite: false })
The text was updated successfully, but these errors were encountered: