# Shared nginx config for tops.ng1–ng3 static previews.
# Language root redirect mirrors taler-ops.ch (Accept-Language → /en|/de|/fr).
# Cache: always revalidate / never store — design previews must show latest HTML/assets.

map $http_accept_language $accept_lang {
    default en;
    ~*^de de;
    ~*^fr fr;
    ~*^en en;
}

server {
    listen 80;
    server_name _;
    root /usr/share/nginx/html;
    index index.html;

    # Relative Location: so Caddy/HTTPS clients stay on https://host/...
    absolute_redirect off;
    port_in_redirect off;
    server_name_in_redirect off;

    # Never serve stale preview content from browser/proxy caches
    etag off;
    if_modified_since off;
    expires -1;
    add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0, private" always;
    add_header Pragma "no-cache" always;
    add_header Expires "0" always;

    # Like https://taler-ops.ch/ — bare root picks language from Accept-Language
    location = / {
        return 302 /$accept_lang/;
    }
    location = /index.html {
        return 302 /$accept_lang/;
    }

    # Bare page names that exist under /{lang}/ (ng2; 302→404 on ng1 if missing)
    location ~ ^/(merchants|users|users-[a-z]+)\.html$ {
        return 302 /$accept_lang$uri;
    }

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