# Example nginx config for stack.perfectprofessionist.com
# React build (dist/) and Laravel (backend/public) share one domain:
#   /api/*  -> Laravel
#   everything else -> React (SPA, falls back to index.html)

server {
    listen 443 ssl http2;
    server_name stack.perfectprofessionist.com;

    ssl_certificate     /etc/letsencrypt/live/stack.perfectprofessionist.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/stack.perfectprofessionist.com/privkey.pem;

    # ---- React build ----
    root /var/www/gulshan-portfolio-app/frontend/dist;
    index index.html;

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

    # ---- Laravel API ----
    # Laravel's own public/ folder, served on the same domain under /api
    location /api {
        root /var/www/gulshan-portfolio-app/backend/public;
        try_files $uri /index.php?$query_string;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php8.3-fpm.sock;   # match your PHP-FPM version
            fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        }
    }
}

server {
    listen 80;
    server_name stack.perfectprofessionist.com;
    return 301 https://$host$request_uri;
}
