Alex Ellis (OpenFaaS Ltd) 49053feac7 Clarify EULA applies to this project since 2019
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2024-11-18 21:20:38 +00:00

32 lines
931 B
Go

// License: OpenFaaS Community Edition (CE) EULA
// Copyright (c) 2017,2019-2024 OpenFaaS Author(s)
// Copyright (c) OpenFaaS Author(s). All rights reserved.
package handlers
import "net/http"
// CORSHandler set custom CORS instructions for the store.
type CORSHandler struct {
Upstream *http.Handler
AllowedHost string
}
func (c CORSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// https://raw.githubusercontent.com/openfaas/store/master/store.json
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
w.Header().Set("Access-Control-Allow-Methods", http.MethodGet)
w.Header().Set("Access-Control-Allow-Origin", c.AllowedHost)
(*c.Upstream).ServeHTTP(w, r)
}
// DecorateWithCORS decorate a handler with CORS-injecting middleware
func DecorateWithCORS(upstream http.Handler, allowedHost string) http.Handler {
return CORSHandler{
Upstream: &upstream,
AllowedHost: allowedHost,
}
}