2022-11-16 23:46:24 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2022-12-09 03:53:16 +01:00
|
|
|
|
|
|
|
"github.com/gorilla/handlers"
|
2022-11-16 23:46:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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-11-16 23:46:24 +01:00
|
|
|
}),
|
2022-12-09 03:53:16 +01:00
|
|
|
handlers.AllowCredentials(),
|
2022-11-16 23:46:24 +01:00
|
|
|
handlers.AllowedMethods([]string{"GET", "POST", "OPTIONS", "DELETE", "PUT"}),
|
|
|
|
handlers.AllowedOrigins([]string{"*"}),
|
|
|
|
)(h)
|
|
|
|
}
|