Skip to content

Commit

Permalink
Adds cors capabilities to management server
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas authored and arekkas committed Dec 12, 2017
1 parent b66462a commit 6519846
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions cmd/serve_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"

"net/http"

"github.com/julienschmidt/httprouter"
Expand All @@ -11,13 +10,15 @@ import (
"github.com/ory/herodot"
"github.com/ory/oathkeeper/rsakey"
"github.com/ory/oathkeeper/rule"
"github.com/rs/cors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/urfave/negroni"
)

type managementConfig struct {
rules rule.Manager
rules rule.Manager
corsPrefix string
}

func runManagement(c *managementConfig) {
Expand All @@ -38,12 +39,14 @@ func runManagement(c *managementConfig) {
n.Use(negronilogrus.NewMiddlewareFromLogger(logger, "oathkeeper-management"))
n.UseHandler(router)

ch := cors.New(parseCorsOptions(c.corsPrefix)).Handler(n)

go refreshKeys(keyManager, 0)

addr := fmt.Sprintf("%s:%s", viper.GetString("MANAGEMENT_HOST"), viper.GetString("MANAGEMENT_PORT"))
server := graceful.WithDefaults(&http.Server{
Addr: addr,
Handler: router,
Handler: ch,
})

logger.Printf("Listening on %s.\n", addr)
Expand Down
5 changes: 3 additions & 2 deletions cmd/serve_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
)

type proxyConfig struct {
rules rule.Manager
rules rule.Manager
corsPrefix string
}

// proxyCmd represents the proxy command
Expand Down Expand Up @@ -160,7 +161,7 @@ func runProxy(c *proxyConfig) {
n.Use(segmentMiddleware)
n.UseHandler(proxy)

ch := cors.New(parseCorsOptions("")).Handler(n)
ch := cors.New(parseCorsOptions(c.corsPrefix)).Handler(n)

var cert tls.Certificate
tlsCert := viper.GetString("HTTP_TLS_CERT")
Expand Down

0 comments on commit 6519846

Please sign in to comment.