cmd: Properly parses CORS env vars
Closes
@@ -26,12 +26,16 @@ import (
"net/http"
"net/url"
"os"
- "strconv"
- "strings"
+
+
+
+
+
"github.com/gorilla/context"
"github.com/julienschmidt/httprouter"
"github.com/meatballhat/negroni-logrus"
+ "github.com/ory/go-convenience/corsx"
"github.com/ory/graceful"
"github.com/ory/herodot"
"github.com/ory/hydra/client"
@@ -43,27 +47,12 @@ import (
"github.com/pkg/errors"
"github.com/rs/cors"
"github.com/spf13/cobra"
- "github.com/spf13/viper"
"github.com/urfave/negroni"
+
)
var _ = &consent.Handler{}
-func parseCorsOptions() cors.Options {
- allowCredentials, _ := strconv.ParseBool(viper.GetString("CORS_ALLOWED_CREDENTIALS"))
- debug, _ := strconv.ParseBool(viper.GetString("CORS_DEBUG"))
- maxAge, _ := strconv.Atoi(viper.GetString("CORS_MAX_AGE"))
- return cors.Options{
- AllowedOrigins: strings.Split(viper.GetString("CORS_ALLOWED_ORIGINS"), ","),
- AllowedMethods: strings.Split(viper.GetString("CORS_ALLOWED_METHODS"), ","),
- AllowedHeaders: strings.Split(viper.GetString("CORS_ALLOWED_HEADERS"), ","),
- ExposedHeaders: strings.Split(viper.GetString("CORS_EXPOSED_HEADERS"), ","),
- AllowCredentials: allowCredentials,
- MaxAge: maxAge,
- Debug: debug,
- }
-}
-
func RunHost(c *config.Config) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
fmt.Println(banner)
@@ -102,7 +91,7 @@ func RunHost(c *config.Config) func(cmd *cobra.Command, args []string) {
n.Use(negronilogrus.NewMiddlewareFromLogger(logger, c.Issuer))
n.UseFunc(serverHandler.rejectInsecureRequests)
n.UseHandler(router)
- corsHandler := cors.New(parseCorsOptions()).Handler(n)
+ corsHandler := cors.New(corsx.ParseOptions()).Handler(n)
var srv = graceful.WithDefaults(&http.Server{
Addr: c.GetAddress(),
