hono
hono copied to clipboard
Provide a way to skip `.route()` group prefixing for certain routes / methods
What is the feature you are proposing?
Linking with NamesMT/hono-adapter-aws-lambda#1
The linked repo is my fork of hono/aws-lambda
adapter, which adds support for LambdaTriggerEvents like S3, SQS triggers.
The support works by registering routes on TRIGGER
method, like:
TRIGGER aws:s3
, in which, the eventSource
, which is aws:s3
, should never be prefixed.
A way to skip .route()
group prefixing for certain routes/methods would be amazing.
Hi @NamesMT
I'm sorry. I can't fully understand what you are intending. Could you share the expected API with the actual code?
Hi @yusukebe,
The following patch is a rough example of the feature (skipping subPath for certain methods):
diff --git a/src/hono-base.ts b/src/hono-base.ts
index d849fce..ae04e49 100644
--- a/src/hono-base.ts
+++ b/src/hono-base.ts
@@ -186,7 +186,10 @@ class Hono<
SubBasePath extends string
>(
path: SubPath,
- app?: Hono<SubEnv, SubSchema, SubBasePath>
+ app?: Hono<SubEnv, SubSchema, SubBasePath>,
+ options?: {
+ noSubPathMethods: string[]
+ }
): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath> {
const subApp = this.basePath(path)
@@ -205,7 +208,10 @@ class Hono<
;(handler as any)[COMPOSED_HANDLER] = r.handler
}
- subApp.addRoute(r.method, r.path, handler)
+ if (options?.noSubPathMethods?.includes(r.method)) {
+ app.addRoute(r.method, r.path, handler)
+ } else
+ subApp.addRoute(r.method, r.path, handler)
})
return this
}
Expected behavior:
childApp.get('/G', c => c.text('hello'))
childApp.post('/P', c => c.text('hello'))
app.route('/child', appC, { noSubPathMethods: ['POST'] } ) // => GET /child/G, POST /P
Thanks! @NamesMT
I got it well. Give me a minute to think about it.