Open
Conversation
91b7f8f to
b148db4
Compare
b148db4 to
ebf9231
Compare
Member
|
Hey @G4brym If you want to get a base path in a handler, you can use the Have you checked it? |
Author
|
Hey @yusukebe, thanks for the pointer! for example: const app = new Hono().basePath('/api')
const router = fromHono(app) // ← need to know "/api" here, no `c` exists yet |
Author
|
or maybe the basePath helper function could be updated to also work with Hono apps, like: import {
basePath,
} from 'hono/route'
const subApp = new Hono()
const path = basePath(subApp) // '/api'
app.route('/:sub', subApp)i can update the pr if you agree with this change |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
getBasePath()public method to theHonoclass, exposing the current base path of a Hono instance without relying on the private_basePathproperty.Motivation
Currently, the only way to read a Hono instance's base path at runtime is by accessing the private
_basePathproperty. This is fragile — it's not part of the public API and could break without notice.Libraries that integrate with Hono (such as chanfana, an OpenAPI schema generator) need to detect the base path to correctly generate API documentation and route schemas. Right now, chanfana reads
_basePathdefensively with runtime type guards (see PR), but a proper public API would be much better.Changes
src/hono-base.ts— AddedgetBasePath(): stringmethod onHonoBasethat returns the current_basePathvaluesrc/hono.test.ts— Added 4 tests:"/"for a fresh instancebasePath()basePath()callsbasePath()creates a cloneUsage
All 205 tests in
src/hono.test.tspass.This PR was generated with AI assistance (OpenCode).