apiVersion: v1
kind: ConfigMap
metadata:
  name: compound-subgraph-wrapper-proxy-config
  namespace: default
data:
  nginx.conf: |
    events {}
    http {
      # See http://nginx.org/en/docs/http/websocket.html
      map $http_upgrade $connection_upgrade {
          default upgrade;
          ''      close;
      }

      server {
        location = / {
          # Health check for ingress
          if ($request_method = GET) {
            return 200 "Ok\n";
          }
        }

        # Replace any URL that's longer than `/` with `/graphql` to proxy
        # these requests to the wrapper.
        rewrite ^/.+$ /graphql;

        location / {
          # Rewrite the URL for the proxy and stop rewriting so
          # we don't trigger the above `location = /` match.
          rewrite ^.*$ / break;

          # Proxy configuration.
          proxy_pass http://127.0.0.1:9500/;
          proxy_http_version 1.1;
          proxy_set_header Connection $connection_upgrade;
          proxy_set_header Host $host;
          proxy_set_header Upgrade $http_upgrade;
          proxy_cache_bypass $http_upgrade;

          # Gateway timeout.
          proxy_read_timeout 3600s;
          proxy_send_timeout 3600s;
        }
      }

      log_format timed '$remote_addr - $remote_user [$time_local] '
            '"$request" $status $body_bytes_sent '
            '"$http_referer" "$http_user_agent" '
            '$request_time $upstream_response_time $pipe';

      access_log /var/log/nginx/access.log timed;
    }
    stream {}
