From 1e82ee11923d45bbb93a33ef34608c87501f6fd6 Mon Sep 17 00:00:00 2001 From: Krishna Srinivas Date: Mon, 31 Aug 2015 14:40:12 -0700 Subject: [PATCH] Add CORS support to minio s3 server --- pkg/server/api/generic-handlers.go | 5 +++++ pkg/server/router.go | 1 + 2 files changed, 6 insertions(+) diff --git a/pkg/server/api/generic-handlers.go b/pkg/server/api/generic-handlers.go index b6afeed4f..c20cbfc14 100644 --- a/pkg/server/api/generic-handlers.go +++ b/pkg/server/api/generic-handlers.go @@ -22,6 +22,7 @@ import ( "time" "github.com/minio/minio/pkg/auth" + "github.com/rs/cors" ) type contentTypeHandler struct { @@ -150,6 +151,10 @@ func (h validateAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } +func CorsHandler(h http.Handler) http.Handler { + return cors.Default().Handler(h) +} + // IgnoreResourcesHandler - // Ignore resources handler is wrapper handler used for API request resource validation // Since we do not support all the S3 queries, it is necessary for us to throw back a diff --git a/pkg/server/router.go b/pkg/server/router.go index 6afff637d..1ba940b0a 100644 --- a/pkg/server/router.go +++ b/pkg/server/router.go @@ -85,6 +85,7 @@ func registerCustomMiddleware(mux http.Handler, conf api.Config) http.Handler { api.IgnoreResourcesHandler, api.ValidateAuthHeaderHandler, api.LoggingHandler, + api.CorsHandler, // Add new your new middleware here )