mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-11 02:47:05 +00:00
27 lines
515 B
Go
27 lines
515 B
Go
package middleware
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/rs/cors"
|
|
|
|
"github.com/nais/wonderwall/pkg/config"
|
|
)
|
|
|
|
func Cors(cfg *config.Config, methods []string) func(http.Handler) http.Handler {
|
|
ssoDomain := strings.TrimPrefix(cfg.SSO.Domain, ".")
|
|
|
|
allowedOrigins := []string{
|
|
fmt.Sprintf("https://*.%s", ssoDomain),
|
|
fmt.Sprintf("https://%s", ssoDomain),
|
|
}
|
|
|
|
return cors.New(cors.Options{
|
|
AllowedOrigins: allowedOrigins,
|
|
AllowedMethods: methods,
|
|
AllowCredentials: true,
|
|
}).Handler
|
|
}
|