avatar proxy - allow more requests and turn logging off
This commit is contained in:
@@ -77,6 +77,7 @@ const (
|
||||
LogAll LoggerFlag = iota
|
||||
LogUser
|
||||
LogBody
|
||||
LogNone
|
||||
)
|
||||
const maxBody = 1024
|
||||
|
||||
@@ -97,6 +98,12 @@ func Logger(flags ...LoggerFlag) func(http.Handler) http.Handler {
|
||||
f := func(h http.Handler) http.Handler {
|
||||
|
||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if inFlags(LogNone) { // skip logging
|
||||
h.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
ww := middleware.NewWrapResponseWriter(w, 1)
|
||||
|
||||
body, user := func() (body string, user string) {
|
||||
|
||||
@@ -82,7 +82,11 @@ func (s *Rest) Run(port int) {
|
||||
}
|
||||
})
|
||||
|
||||
router.Mount(s.Authenticator.AvatarProxy.Routes()) // mount avatars controller to /api/v1/avatar/{file.img}
|
||||
avatarMiddlewares := []func(http.Handler) http.Handler{
|
||||
Logger(LogNone),
|
||||
tollbooth_chi.LimitHandler(tollbooth.NewLimiter(100, nil)),
|
||||
}
|
||||
router.Mount(s.Authenticator.AvatarProxy.Routes(avatarMiddlewares...)) // mount avatars controller to /api/v1/avatar/{file.img}
|
||||
|
||||
// api routes
|
||||
router.Route("/api/v1", func(rapi chi.Router) {
|
||||
|
||||
@@ -85,8 +85,9 @@ func (p *Proxy) Put(u store.User) (avatarURL string, err error) {
|
||||
}
|
||||
|
||||
// Routes returns auth routes for given provider
|
||||
func (p *Proxy) Routes() (string, chi.Router) {
|
||||
func (p *Proxy) Routes(middlewares ...func(http.Handler) http.Handler) (string, chi.Router) {
|
||||
router := chi.NewRouter()
|
||||
router.Use(middlewares...)
|
||||
|
||||
// GET /123456789.image
|
||||
router.Get("/{avatar}", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user