WASAPhoto/cmd/webapi/cors.go

23 lines
690 B
Go
Raw Permalink Normal View History

package main
import (
"net/http"
2022-12-09 03:53:16 +01:00
"github.com/gorilla/handlers"
)
// applyCORSHandler applies a CORS policy to the router. CORS stands for Cross-Origin Resource Sharing: it's a security
// feature present in web browsers that blocks JavaScript requests going across different domains if not specified in a
// policy. This function sends the policy of this API server.
func applyCORSHandler(h http.Handler) http.Handler {
return handlers.CORS(
handlers.AllowedHeaders([]string{
2022-12-09 03:53:16 +01:00
"Content-Type",
"Authorization",
}),
2022-12-09 03:53:16 +01:00
handlers.AllowCredentials(),
handlers.AllowedMethods([]string{"GET", "POST", "OPTIONS", "DELETE", "PUT"}),
handlers.AllowedOrigins([]string{"*"}),
)(h)
}