apiVersion: v1
data:
  nginx.conf: |-
    user       nginx;
    worker_processes  5;
    worker_rlimit_nofile 8192;
    events {
        worker_connections  4096;
    }

    http {
        index    index.html index.htm index.php;
        default_type application/octet-stream;
        log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
        sendfile on;
        tcp_nopush   on;
        server_names_hash_bucket_size 128;
        server {
            listen 80;
            {{ if .Values.ui.enabled}}
            location / {
                proxy_http_version 1.1;
                proxy_pass http://charlescd-ui:3000;
            }
            {{- end}}
            {{ if .Values.moove.enabled}}
            location /moove/ {
                proxy_http_version 1.1;
                proxy_pass http://charlescd-moove:8080/;
                if ($request_method = 'OPTIONS') {
                    add_header 'Access-Control-Allow-Origin' 'http://localhost:3000,http://localhost:3001,http://localhost:8081,http://localhost:8080,http://charles.info.example';
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'Authorization,x-circle-id,x-workspace-id,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                    add_header 'Access-Control-Max-Age' 1728000;
                    add_header 'Content-Type' 'text/plain; charset=utf-8';
                    add_header 'Content-Length' 0;
                    return 204;
                 }
                 if ($request_method = 'POST') {
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'Authorization,x-circle-id,x-workspace-id,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                    add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
                 }
                 if ($request_method = 'GET') {
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'Authorization,x-circle-id,x-workspace-id,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                    add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
                 }
            }
            {{- end}}
            {{ if .Values.octopipe.enabled}}
            location /octopipe/ {
                proxy_http_version 1.1;
                proxy_pass http://charlescd-octopipe:8080/;
            }
            {{- end}}
            {{ if .Values.circlematcher.enabled}}
            location /charlescd-circle-matcher {
                proxy_http_version 1.1;
                proxy_pass http://charlescd-circle-matcher:8080/;
                if ($request_method = 'OPTIONS') {
                    add_header 'Access-Control-Allow-Origin' 'http://localhost:3000,http://localhost:3001,http://localhost:8081,http://localhost:8080,http://charles.info.example';
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'Authorization,x-circle-id,x-workspace-id,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                    add_header 'Access-Control-Max-Age' 1728000;
                    add_header 'Content-Type' 'text/plain; charset=utf-8';
                    add_header 'Content-Length' 0;
                    return 204;
                 }
                 if ($request_method = 'POST') {
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'Authorization,x-circle-id,x-workspace-id,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                    add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
                 }
                 if ($request_method = 'GET') {
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'Authorization,x-circle-id,x-workspace-id,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                    add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
                 }
            }
            {{- end}}
            {{ if .Values.keycloak.enabled}}
            location ^~ /keycloak/ {
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection ‘upgrade’;
                proxy_set_header Host $host;
                proxy_pass      http://charlescd-keycloak-http;
            }
            {{- end}}
        }
    }
kind: ConfigMap
metadata:
  name: confnginx
