worker_processes 1;

events { worker_connections 1024; }

http {

    sendfile on;

    upstream docker-front {
        server front:4200;
    }

    upstream docker-back {
        server back:8000;
    }

    server {
        listen 80;

        location / {
            proxy_pass         http://docker-front;
            proxy_redirect     off;
            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-Host $server_name;
        }

        location /contracts/signature/ {
            set $is_robot 0;
            if ($http_user_agent ~* "Discordbot|googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp") {
                rewrite /contracts/signature/(.*) /api/v1/contract/print/opengraph/$1 last;
                proxy_pass         http://docker-back;
                break;
                set $is_robot 1;
            }

            if ($is_robot = 0) {
                proxy_pass         http://docker-front;
            }

            proxy_redirect     off;
            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-Host $server_name;
        }

        location /api/v1/ {
            proxy_pass         http://docker-back/;
            proxy_redirect     off;
            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-Host $server_name;
        }

         location /ng-cli-ws {
           proxy_pass http://docker-front ;
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "Upgrade";
           proxy_set_header Host $host;
         }
    }
}