kind: ConfigMap
apiVersion: v1
metadata:
  name: laracon2019-nginx
data:
  nginx.conf: |
    user www-data;
    worker_processes auto;
    pid /run/nginx.pid;

    events {}
    http {
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      client_max_body_size 50M;

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

      gzip on;
      gzip_vary on;
      gzip_proxied any;
      gzip_comp_level 6;
      gzip_buffers 16 8k;
      gzip_min_length 256;
      gzip_http_version 1.1;
      gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

      server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html/public;
        server_name _;

        location / {
          if ($REQUEST_METHOD = 'OPTIONS') {
            # add CORS headers
            add_header 'Access-Control-Allow-Origin' '$http_origin';
            add_header 'Access-Control-Allow-Methods' 'POST, GET, DELETE, PUT, PATCH, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, Accept, Content-Type, X-Request-With, X-XSRF-TOKEN';
            add_header 'Access-Control-Allow-Credentials' 'true';

            # Make this preflight request valid for 20 days
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain; charset=utf-8';
            add_header 'Content-Length' 0;
            return 204;
          }

          try_files $uri /index.php?$args;
        }

        location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param REQUEST_METHOD $request_method;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_pass 127.0.0.1:9000;

          add_header 'Access-Control-Allow-Origin' '$http_origin' always;
          add_header 'Access-Control-Allow-Methods' 'POST, GET, DELETE, PUT, PATCH, OPTIONS' always;
          add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, Accept, Content-Type, X-Request-With, X-XSRF-TOKEN' always;
          add_header 'Access-Control-Allow-Credentials' 'true' always;
        }
      }
    }
