# Redirects bare https://apexturf.es/* -> https://www.apexturf.es/* (301).
# Needs cert-manager to issue a cert for the bare domain too (browsers hit
# TLS on apexturf.es *before* any HTTP-level redirect can happen), so this
# still requests its own certificate even though all traffic bounces onward.
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: redirect-to-www
  namespace: apex-turf
spec:
  redirectRegex:
    regex: ^https?://apexturf\.es/(.*)
    replacement: https://www.apexturf.es/${1}
    permanent: true
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: apex-turf-redirect
  namespace: apex-turf
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    traefik.ingress.kubernetes.io/router.middlewares: apex-turf-redirect-to-www@kubernetescrd
spec:
  ingressClassName: traefik
  tls:
    - hosts:
        - apexturf.es
      secretName: apex-turf-root-tls
  rules:
    - host: apexturf.es
      http:
        paths:
          # Backend is never actually reached — the middleware above redirects
          # first — but Ingress requires a rule to attach the middleware to.
          - path: /
            pathType: Prefix
            backend:
              service:
                name: apex-turf-web
                port:
                  number: 80
