Skip to content

Using Custom Middleware on a per route basis? #389

Answered by danielgtaylor
joa23 asked this question in Q&A
Discussion options

You must be logged in to vote

@joa23 for router-agnostic middleware, you can use huma.Operation.Middlewares when registering the operation.

However, it looks like your middleware requires the use of the stdlib http.Handler/http.HandlerFunc and you won't have access to the raw request/response at the Huma level. The middleware is just a few lines, so maybe you could rewrite it as a Huma middleware, see https://github.com/zitadel/zitadel-go/blob/next/pkg/http/middleware/authz.go.

Alternatively you could write a middleware for your underlying router that only calls this middleware if the patch matches some prefix.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@joa23
Comment options

Answer selected by joa23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants