mirror of
https://github.com/openfaas/faas.git
synced 2025-06-22 06:43:23 +00:00
Allow CORS to GitHub raw
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
24
gateway/handlers/cors.go
Normal file
24
gateway/handlers/cors.go
Normal file
@ -0,0 +1,24 @@
|
||||
package handlers
|
||||
|
||||
import "net/http"
|
||||
|
||||
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", "GET")
|
||||
w.Header().Set("Access-Control-Allow-Origin", c.AllowedHost)
|
||||
|
||||
(*c.Upstream).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func DecorateWithCORS(upstream http.Handler, allowedHost string) http.Handler {
|
||||
return CorsHandler{
|
||||
Upstream: &upstream,
|
||||
AllowedHost: allowedHost,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user