apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx
data:
  nginx.conf: |+
    worker_processes auto;
    pid /tmp/nginx.pid;
    error_log               /dev/stderr warn;

    events {
      worker_connections 1024;
      use epoll;
      multi_accept on;
    }

    http {
      client_body_temp_path /tmp/client_body_temp;
      proxy_temp_path /tmp/proxy_temp;
      fastcgi_temp_path /tmp/fastcgi_temp;
      uwsgi_temp_path /tmp/uwsgi_temp;
      scgi_temp_path /tmp/scgi_temp;
      tcp_nodelay on;

      # this is necessary for us to be able to disable request buffering in all cases
      proxy_http_version 1.1;

      upstream api {
        server "cequel-space-api:80";
      }

      upstream app {
        server "cequel-space-app:80";
      }

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

      access_log /dev/stdout timed_combined;

      server {
        listen 8080;
        server_tokens off;

        # Add extra headers
        add_header X-Frame-Options DENY;
        add_header Content-Security-Policy "frame-ancestors 'none'";

        location /api/ {
          proxy_pass http://api;
          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 http;

          proxy_buffering off;
          proxy_request_buffering off;
        }

        location /swagger/ {
          proxy_pass http://api;
          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 http;

          proxy_buffering off;
          proxy_request_buffering off;
        }
        
        location / {
          proxy_pass http://app/;
          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 http;

          proxy_buffering off;
          proxy_request_buffering off;
        }
      }
    }

