Skip to content

Commit eeb4050

Browse files
authored
Merge pull request #11 from commitdev/move-cors-to-ingress
#10 : Move cors handling to ingress instead of application, as people…
2 parents de5fa04 + 850be79 commit eeb4050

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

kubernetes/overlays/production/ingress.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ metadata:
1111
cert-manager.io/cluster-issuer: clusterissuer-letsencrypt-production
1212
# external-dns
1313
external-dns.alpha.kubernetes.io/hostname: <% index .Params `productionBackendHost` %>
14+
# CORS
15+
nginx.ingress.kubernetes.io/enable-cors: "true"
16+
nginx.ingress.kubernetes.io/cors-allow-origin: "https://<% index .Params `productionFrontendHost` %>/"
1417

1518
spec:
1619
rules:

kubernetes/overlays/staging/ingress.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ metadata:
1111
cert-manager.io/cluster-issuer: clusterissuer-letsencrypt-production
1212
# external-dns
1313
external-dns.alpha.kubernetes.io/hostname: <% index .Params `stagingBackendHost` %>
14+
# CORS
15+
nginx.ingress.kubernetes.io/enable-cors: "true"
16+
nginx.ingress.kubernetes.io/cors-allow-origin: "https://<% index .Params `stagingFrontendHost` %>/"
1417

1518
spec:
1619
rules:

main.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"strconv"
1313
"syscall"
1414
"time"
15-
16-
"github.com/rs/cors"
1715
)
1816

1917
const gracefulShutdownTimeout = 10 * time.Second
@@ -39,11 +37,8 @@ func main() {
3937
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
4038
})
4139

42-
// Change this to a more strict CORS policy
43-
handler := cors.Default().Handler(r)
44-
4540
serverAddress := fmt.Sprintf("0.0.0.0:%s", os.Getenv("SERVER_PORT"))
46-
server := &http.Server{Addr: serverAddress, Handler: handler}
41+
server := &http.Server{Addr: serverAddress, Handler: r}
4742

4843
// Watch for signals to handle graceful shutdown
4944
stop := make(chan os.Signal, 1)

0 commit comments

Comments
 (0)