server {
    listen 80;
    server_name DOMAIN www.DOMAIN;

    root /var/www/frontend;
    index index.html;

    location / {
        try_files $uri $uri/index.html $uri.html /index.html;
    }

    location /admin/ {
        root /var/www/frontend;
        index index.html;
    }

    location /connect/assets/ {
        root /var/www/frontend;
        expires 30d;
        add_header Cache-Control "public, immutable";
    }

    location ~* _next/static/chunks/791 {
        root /var/www/frontend;
        add_header Cache-Control "no-cache, no-store, must-revalidate";
        add_header Pragma "no-cache";
        add_header Expires "0";
    }

    location /assets/ {
        root /var/www/frontend;
        autoindex off;
    }

    location /api/ {
        if ($request_method = OPTIONS) {
            return 204;
        }

        proxy_pass         http://127.0.0.1:8080/api/;
        proxy_set_header   Host                $host;
        proxy_set_header   X-Forwarded-For     $proxy_add_x_forwarded_for;
        proxy_set_header   X-Real-IP           $remote_addr;

        add_header Access-Control-Allow-Origin  "*" always;
        add_header Access-Control-Allow-Methods "GET, POST, PUT, OPTIONS" always;
        add_header Access-Control-Allow-Headers "*" always;
    }
}
