apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-well-known-config
data:
  default.conf: |
    server {
      listen 8080;
      server_name _;

      # Well-known endpoint for Bitwarden clients (multiple variations)
      location /.well-known/bitwarden/ {
        default_type application/json;
        add_header Content-Type application/json always;
        add_header Access-Control-Allow-Origin * always;
        return 200 '{"object":"bitwarden-bitwarden-host","api":"https://vaultwarden.lotimmy.com"}';
      }

      location = /.well-known/bitwarden {
        default_type application/json;
        add_header Content-Type application/json always;
        add_header Access-Control-Allow-Origin * always;
        return 200 '{"object":"bitwarden-bitwarden-host","api":"https://vaultwarden.lotimmy.com"}';
      }

      # Forward all other requests to Vaultwarden
      location / {
          proxy_pass http://127.0.0.1:80;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;

          # WebSocket support
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
      }
    }
