Replies: 2 comments 2 replies
-
I was going to say that named path parameters are not a universal concept, but in fact, many servers do implement this feature (fastify, express, hattip, hono, h3). For servers that support it, I could add route parameters under the runtime argument (which is not yet documented, as its still WIP). But what to do when an adapter does not support support it? For instance the Cloudflare adapter as no concept of routes. I guess that something like that could do the trick: import { parseRoute } from `@universal-middleware/core`;
interface Options {
route?: '/user/:name'
}
export const handler = ((options?: Options) => async (request, context, runtime) => {
const name =
// hypothetical route params on `runtime`
runtime.params?.name ??
// hypothetical `parseRoute` helper as a fallback, using `path-to-regexp` for instance
parseRoute(request, options);
if (!name) throw new Error("'name' route parameter required");
// ...
}) satisfies Get<[Options | undefined], UniversalHandler>; |
Beta Was this translation helpful? Give feedback.
1 reply
-
Added by #29. Route parameters recipe example. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hono supports named path parameters. How would one access those using the UniversalHandler?
Example
Beta Was this translation helpful? Give feedback.
All reactions