_format_version: "2.1"
_transform: true

###
# MC Cars - Kong declarative config
# Routes traffic coming in on the Kong proxy port to each Supabase service.
###

consumers:
  - username: anon
    keyauth_credentials:
      - key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
  - username: service_role
    keyauth_credentials:
      - key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
  - username: dashboard

basicauth_credentials:
  - consumer: dashboard
    username: supabase
    password: mc-cars-studio

acls:
  - consumer: anon
    group: anon
  - consumer: service_role
    group: admin

services:
  ########################################
  # Auth (GoTrue)
  ########################################
  - name: auth-v1
    url: http://auth:9999/
    routes:
      - name: auth-v1-all
        strip_path: true
        paths:
          - /auth/v1/
    plugins:
      - name: cors

  ########################################
  # REST (PostgREST)
  ########################################
  - name: rest-v1
    url: http://rest:3000/
    routes:
      - name: rest-v1-all
        strip_path: true
        paths:
          - /rest/v1/
    plugins:
      - name: cors
      - name: key-auth
        config:
          hide_credentials: false
      - name: acl
        config:
          hide_groups_header: true
          allow:
            - admin
            - anon

  ########################################
  # Realtime (WebSocket subscriptions)
  ########################################
  - name: realtime-v1
    url: http://realtime:4000/socket
    protocol: http
    routes:
      - name: realtime-v1-all
        strip_path: true
        paths:
          - /realtime/v1/
        protocols:
          - http
          - https
    plugins:
      - name: cors
      - name: key-auth
        config:
          hide_credentials: false
      - name: acl
        config:
          hide_groups_header: true
          allow:
            - admin
            - anon

  ########################################
  # Storage
  ########################################
  - name: storage-v1
    url: http://storage:5000/
    routes:
      - name: storage-v1-all
        strip_path: true
        paths:
          - /storage/v1/
    plugins:
      - name: cors

  ########################################
  # postgres-meta (needed by Studio)
  ########################################
  - name: meta
    url: http://meta:8080/
    routes:
      - name: meta-all
        strip_path: true
        paths:
          - /pg/
    plugins:
      - name: key-auth
        config:
          hide_credentials: false
      - name: acl
        config:
          hide_groups_header: true
          allow:
            - admin

  ########################################
  # n8n Webhooks (internal workflow triggers)
  ########################################
  - name: n8n-webhooks
    url: http://n8n:5678/
    routes:
      - name: n8n-webhooks-all
        strip_path: false
        paths:
          - /webhook/
    plugins:
      - name: cors
