-
Notifications
You must be signed in to change notification settings - Fork 577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use specific middleware for specific routes #25
Comments
+1 |
1 similar comment
+1 |
This is where Negroni's modularity excels. If your router supports
With Hope that helps! |
Thank you for the reply. |
Httprouter supports http.Handler with the Handler method. So it should work great. Only limitation is that you won't be getting httprouter params for the top level route in the nesting, but that is a problem with nesting in general. You could possibly make use of closures, but in all likeliness you wouldn't have this restriction work against you in most situations Sent from my iPhone
|
Yup, you can create as many negroni instances as you want, they are just http.Handlers and pretty lightweight.
|
closing as it looks like this issue is resolved |
It would be great if this info was in readme file. |
+1 |
Hi, I'm trying to make this work using gorilla and negroni but I can't seem to find the correct solution. This is the way I'm trying to do this: n := negroni.Classic()
r := mux.NewRouter()
ac := mux.NewRouter()
ac.HandleFunc("/accounts", createHandler)
ac.HandleFunc("/accounts/{id}/password_reset_tokens", sendPasswordResetTokenHandler)
r.Handle("/accounts", negroni.New(
&middleware.BasicAuth{},
negroni.Wrap(ac),
))
n.UseHandler(r)
n.Run(":3000") After negroni starts, if I call the /accounts URI it works and calls the createHandler with the specified middlewares. However, whenever I try to call the /accounts/{id}/password_reset_tokens I get a 404 response from negorni / gorilla. Can you please point me the correct way of applying a middleware for several routes? Thanks!. |
I already found how it should be done. Instead of using That did the trick. |
Thanks @marcosnils. Put me in the right direction. |
@dimroc glad it helped :) |
Hey there :) I might need a bit of help for this. For what I understand, the following should work:
Sadly, I fail to see why any request ends up with a 404 status code. The idea behind that is to be able to execute a middleware only for Any ideas? |
Hey @aubm When you access your endpoints it is handled by
|
Hey @brstos :) Thank you for your answer, it makes sens to me. Cheers, |
I am trying to apply a middleware to the routes with a subrouter, as shown https://github.com/dgraph-io/gru/blob/feature/invite-candidate/gruadmin/main.go#L124. Though the jwt middleware isn't hit and the route is hit directly? |
What is the easiest way to specify a middleware (auth for example) for a group of routes and another middleware (or none) for another group of routes in the same app?
The text was updated successfully, but these errors were encountered: