server {
    listen 80;
    server_name www.tasteby.net tasteby.net;
    return 301 https://www.tasteby.net$request_uri;
}

server {
    listen 80;
    server_name dev.tasteby.net;
    return 301 https://dev.tasteby.net$request_uri;
}

server {
    listen 443 ssl http2;
    server_name dev.tasteby.net;

    ssl_certificate     /etc/letsencrypt/live/dev.tasteby.net/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/dev.tasteby.net/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    # Frontend (Next.js)
    location / {
        proxy_pass http://127.0.0.1:3001;
        proxy_http_version 1.1;
        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-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    # Backend API
    location /api/ {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        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-Proto $scheme;
        proxy_read_timeout 300;
        proxy_connect_timeout 75;
        proxy_send_timeout 300;
    }
}

server {
    listen 443 ssl http2;
    server_name tasteby.net;

    ssl_certificate     /etc/letsencrypt/live/www.tasteby.net/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.tasteby.net/privkey.pem;

    return 301 https://www.tasteby.net$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.tasteby.net;

    ssl_certificate     /etc/letsencrypt/live/www.tasteby.net/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.tasteby.net/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    # Frontend (Next.js)
    location / {
        proxy_pass http://127.0.0.1:3001;
        proxy_http_version 1.1;
        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-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    # Backend API (FastAPI)
    location /api/ {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        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-Proto $scheme;
        proxy_read_timeout 300;
        proxy_connect_timeout 75;
        proxy_send_timeout 300;
    }
}
