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
parent 78c40ab6b4
commit cd171c40cb
4 changed files with 25 additions and 8 deletions
+1 -8
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))
})
}