apiVersion: v1
kind: ConfigMap
metadata:
  name: reverse-proxy-configmap
  namespace: battle-rails
  labels:
    app: reverse-proxy
data:
  nginx.conf: |
    user              nginx;
    worker_processes  auto;

    error_log  stderr info;
    pid        /var/run/nginx.pid;

    timer_resolution  500ms;

    worker_rlimit_nofile 10240;
    events {
        use epoll;
        worker_connections 10240;
    }

    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;

        server_name_in_redirect off;
        server_tokens           off;

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  /dev/stdout  main;

        sendfile    on;
        tcp_nopush  on;

        keepalive_timeout  30;
        tcp_nodelay        off;

        client_body_timeout   10;
        client_header_timeout 10;

        client_header_buffer_size 128;
        client_max_body_size      8m;

        open_file_cache           max=1000 inactive=20s;
        open_file_cache_valid     30s;
        open_file_cache_min_uses  2;
        open_file_cache_errors    on;

        proxy_cache_path  /var/cache/nginx  levels=1:2   keys_zone=cache:80m inactive=1d  max_size=2500m;
        proxy_cache_key   "$scheme$request_method$host$request_uri";
        proxy_cache       cache;

        proxy_temp_path   /tmp;

        proxy_cache_valid  200 302  1d;
        proxy_cache_valid  301      1d;
        proxy_cache_valid  any      1m;

        proxy_ignore_headers  "X-Accel-Redirect" "X-Accel-Expires" "Expires" "Cache-Control" "Set-Cookie";

        proxy_connect_timeout 300;
        proxy_send_timeout    300;
        proxy_read_timeout    300;

        proxy_buffer_size           32k;
        proxy_buffers               4 32k;
        proxy_busy_buffers_size     32k;
        proxy_temp_file_write_size  32k;

        gzip              on;
        gzip_http_version 1.0;
        gzip_disable      "MSIE [1-6]\.(?!.*SV1)";

        gzip_buffers    4 16k;
        gzip_comp_level 2;
        gzip_min_length 0;

        gzip_types    text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        gzip_proxied  expired no-cache no-store private auth;

        server {
            listen 8080;
            server_name default;
            proxy_ssl_server_name on;

            location = /healthcheck {
              return 200 'OK';
            }

            location ~ /pokemon/ {
                proxy_pass https://pokeapi.co;
            }

            location ~ /move/ {
                proxy_pass https://pokeapi.co;
            }

            location ~ ^/battle/?$ {
              proxy_pass http://battle-rails-service:3000;
            }
        }
    }
