apiVersion: v1
kind: ConfigMap
metadata:
  name: scopelens-website-config
  labels:
    app: website
data:
  nginx.conf: |
    user nginx;
    worker_processes 1;
    error_log /var/log/nginx/error.log warn;
    pid /var/run/nginx.pid;
    events
    {
      worker_connections 1024;
    }
    http
    {
      include       /etc/nginx/mime.types;
      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"';

      access_log /var/log/nginx/access.log main;
      sendfile on;
      keepalive_timeout 65;
      gzip on;

      upstream Scopelens
      {
        # scopelens-server-service is the internal DNS name used by the backend Service inside Kubernetes
        server scopelens-server-service;
      }
      upstream Classifier
      {
        server pokemon-classifier-service;
      }

      server
      {
        listen 80;
        server_name localhost;
        # website
        location /
        {
          proxy_http_version 1.1;
          root /app;
          index index.html;
          try_files $uri $uri/ /index.html;
        }
        # main service
        location /api/
        {
          proxy_http_version 1.1;
          proxy_pass http://Scopelens;
        }
        # deep learning service
        location /advapi/
        {
          proxy_http_version 1.1;
          proxy_pass http://Classifier;
        }
        # static resources
        location /assets/
        {
          proxy_http_version 1.1;
          proxy_pass http://Scopelens;
        }
        # forbidden paths
        location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
        {
          proxy_http_version 1.1;
          return 404;
        }

        error_page 404 /404.html;
        location = /404.html
        {
          proxy_http_version 1.1;
          root /usr/share/nginx/html;
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html
        {
          proxy_http_version 1.1;
          root /usr/share/nginx/html;
        }
      }
    }