#!/bin/sh
set -eu

SERVER_NAME="${1:-ai.clawdie.si}"
ROOT_DIR="${2:-/usr/local/www/ai.clawdie.si}"
SCREENSHOT_DIR="${3:-/usr/local/www/ai.clawdie.si/screenshots}"

cat <<EOF
server {
    listen 80;
    listen [::]:80;
    server_name ${SERVER_NAME};

    root ${ROOT_DIR};
    index index.html;

    location = /latest.json {
        add_header Cache-Control "no-store";
        try_files \$uri =404;
    }

    location = / {
        add_header Cache-Control "no-store";
        try_files \$uri /index.html;
    }

    location /screenshots/ {
        alias ${SCREENSHOT_DIR}/;
        add_header Cache-Control "public, max-age=31536000, immutable";
    }
}
EOF

