# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config-listener
data:
  nginx.conf: |-
    worker_processes 1;
    worker_rlimit_nofile 4096;
    error_log /proc/1/fd/1 warn;
    pid /var/run/nginx.pid;
    events {
      worker_connections 4096;
      accept_mutex off;
    }
    http {
      server_tokens off;
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
      log_format  main  '[nginx] method=$request_method path=$request_uri '
                        'status=$status duration=$request_time size=$body_bytes_sent '
                        '"$remote_user" "$http_referer" "$http_user_agent"';
      # Log to stdout.
      # Use the stdout of init on Docker to get the logs to the log drain.
      #
      access_log /proc/1/fd/1 main;

      # productcatalogservice
      server {
        listen 4443 ssl http2;
        ssl_certificate /etc/nginx/ssl/tls.crt;
        ssl_certificate_key /etc/nginx/ssl/tls.key;
        location / {
            grpc_pass grpc://productcatalogservice:3550;
        }
      }
      # currencyservice
      server {
        listen 4444 ssl http2;
        ssl_certificate /etc/nginx/ssl/tls.crt;
        ssl_certificate_key /etc/nginx/ssl/tls.key;
        location / {
            grpc_pass grpc://currencyservice:7000;
        }
      }
      # cartservice
      server {
        listen 4445 ssl http2;
        ssl_certificate /etc/nginx/ssl/tls.crt;
        ssl_certificate_key /etc/nginx/ssl/tls.key;
        location / {
            grpc_pass grpc://cartservice:7070;
        }
      }
      # recommendationservice
      server {
        listen 4446 ssl http2;
        ssl_certificate /etc/nginx/ssl/tls.crt;
        ssl_certificate_key /etc/nginx/ssl/tls.key;
        location / {
            grpc_pass grpc://recommendationservice:8080;
        }
      }
      # shippingservice
      server {
        listen 4447 ssl http2;
        ssl_certificate /etc/nginx/ssl/tls.crt;
        ssl_certificate_key /etc/nginx/ssl/tls.key;
        location / {
            grpc_pass grpc://shippingservice:50051;
        }
      }
      # adservice
      server {
        listen 4448 ssl http2;
        ssl_certificate /etc/nginx/ssl/tls.crt;
        ssl_certificate_key /etc/nginx/ssl/tls.key;
        location / {
            grpc_pass grpc://adservice:9555;
        }
      }
      # emailservice
      server {
        listen 4449 ssl http2;
        ssl_certificate /etc/nginx/ssl/tls.crt;
        ssl_certificate_key /etc/nginx/ssl/tls.key;
        location / {
            grpc_pass grpc://emailservice:5000;
        }
      }
    }
