upstream frontend {
    server frontend:3000;
}

upstream backend {
    server backend:3001;
    keepalive 20;
}

server {
    listen 80;

    autoindex on;
    root /usr/share/nginx/html;
    index index.html index.php;

    location / {
        proxy_pass http://frontend;
    }

    location /sockjs-node {
        proxy_pass http://frontend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    location /game {
        absolute_redirect off;
        rewrite ^([^.]*[^/])$ $1/ redirect;
        alias /usr/share/nginx/html;
    }

    location /api/v1 {
        rewrite /api/v1(?:/(.*))? /$1 break;
        proxy_pass http://backend;
        client_max_body_size 100M;
    }
}
