-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
149 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cors | ||
|
||
import ( | ||
"github.com/cernbox/reva/pkg/log" | ||
|
||
"github.com/cernbox/reva/cmd/revad/httpserver" | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/rs/cors" | ||
) | ||
|
||
func init() { | ||
httpserver.RegisterMiddleware("cors", New) | ||
} | ||
|
||
var logger = log.New("cors") | ||
|
||
type config struct { | ||
AllowedOrigins []string `mapstructure:"allowed_origins"` | ||
AllowCredentials bool `mapstructure:"allow_credentials"` | ||
AllowedMethods []string `mapstructure:"allowed_methods"` | ||
AllowedHeaders []string `mapstructure:"allowed_headers"` | ||
ExposedHeaders []string `mapstructure:"exposed_headers"` | ||
MaxAge int `mapstructure:"max_age"` | ||
OptionsPassthrough bool `mapstructure:"options_passthrough"` | ||
} | ||
|
||
// New creates a new CORS middleware. | ||
func New(m map[string]interface{}) (httpserver.Middleware, error) { | ||
conf := &config{} | ||
if err := mapstructure.Decode(m, conf); err != nil { | ||
return nil, err | ||
} | ||
|
||
c := cors.New(cors.Options{ | ||
AllowCredentials: conf.AllowCredentials, | ||
AllowedHeaders: conf.AllowedHeaders, | ||
AllowedMethods: conf.AllowedMethods, | ||
AllowedOrigins: conf.AllowedOrigins, | ||
ExposedHeaders: conf.ExposedHeaders, | ||
MaxAge: conf.MaxAge, | ||
OptionsPassthrough: conf.OptionsPassthrough, | ||
}) | ||
|
||
return c.Handler, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
// Handlers is a map of all registered handlers to be used from http services. | ||
var Handlers = map[string]HandlerChain{} | ||
|
||
// HandlerChain is the the type that http handlers need to register. | ||
type HandlerChain func(http.Handler) http.Handler | ||
|
||
// Register register a handler chain. | ||
func Register(name string, chain HandlerChain) { | ||
Handlers[name] = chain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package loader | ||
|
||
import ( | ||
// Load core HTTP middlewares. | ||
_ "github.com/cernbox/reva/cmd/revad/svcs/httpsvcs/handlers/auth" | ||
_ "github.com/cernbox/reva/cmd/revad/svcs/httpsvcs/handlers/cors" | ||
// Add your own middlware. | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters