...

Source file src/github.com/cybertec-postgresql/pgwatch/v3/internal/webserver/cors.go

Documentation: github.com/cybertec-postgresql/pgwatch/v3/internal/webserver

     1  package webserver
     2  
     3  import (
     4  	"net/http"
     5  )
     6  
     7  func corsMiddleware(next http.Handler) http.Handler {
     8  	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
     9  		w.Header().Set("Access-Control-Allow-Origin", "http://localhost:4000") //check internal/webui/.env
    10  		w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
    11  		w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, token")
    12  		if r.Method == "OPTIONS" {
    13  			w.WriteHeader(http.StatusOK)
    14  			return
    15  		}
    16  		next.ServeHTTP(w, r)
    17  	})
    18  }
    19