Add secure middleware, with sensible values

This commit is contained in:
Deluan 2020-10-04 14:29:33 -04:00 • committed by Deluan Quintão
commit cd171c40cb
4 changed files with 25 additions and 8 deletions

View file

@ -53,6 +53,7 @@ func (a *Server) Run(addr string) {
func (a *Server) initRoutes() {
r := chi.NewRouter()
r.Use(secureMiddleware())
r.Use(cors.AllowAll().Handler)
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
@ -88,11 +89,3 @@ func (a *Server) initScanner() {
}
}()
}
func injectLogger(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = log.NewContext(r.Context(), "requestId", ctx.Value(middleware.RequestIDKey))
next.ServeHTTP(w, r.WithContext(ctx))
})
}