diff --git a/cinny/lotus_deploy.sh b/cinny/lotus_deploy.sh index 2eb0f73..f1e1ab1 100755 --- a/cinny/lotus_deploy.sh +++ b/cinny/lotus_deploy.sh @@ -160,7 +160,13 @@ echo "[$(date '+%Y-%m-%d %H:%M:%S')] Deploying to $WEBROOT..." # /var/www/html/config.json by lxc106-cinny.sh. The build ships a DEV default # (allowCustomHomeservers:true); rsyncing it would clobber the production config # on every deploy. Keep the app bundle and the runtime config separate. -rsync -a --delete --exclude config.json dist/ "$WEBROOT/" +# [matrix #23] Keep the previous builds' hashed assets for a while: a browser +# still holding an older index.html (or service-worker precache) asks for its +# assets/index-.js, and deleting them on every deploy broke the app +# for those users until their cached shell expired. Prune after 14 days. +rsync -a --delete --exclude config.json --exclude assets/ dist/ "$WEBROOT/" +rsync -a dist/assets/ "$WEBROOT/assets/" +find "$WEBROOT/assets" -type f -mtime +14 -delete echo "[$(date '+%Y-%m-%d %H:%M:%S')] ===== Deploy complete ($VITE_APP_VERSION) =====" diff --git a/cinny/nginx.conf b/cinny/nginx.conf index 6e4a797..97dbd41 100644 --- a/cinny/nginx.conf +++ b/cinny/nginx.conf @@ -1,3 +1,12 @@ +# [matrix #23] SPA routes (/, /home/…, /login/…) are rewritten to /index.html +# inside `location /`, where no cache headers were set: browsers then reused a +# heuristically fresh shell after a deploy and requested deleted assets. Only +# the rewritten shell gets no-cache; other files there keep their defaults. +map $uri $lotus_shell_cache_control { + /index.html "no-cache, no-store, must-revalidate"; + default ""; +} + server { listen 80; listen [::]:80; @@ -99,6 +108,9 @@ server { } location / { + # add_header here drops the server-level headers, so include them again. + include snippets/cinny-security-headers.conf; + add_header Cache-Control $lotus_shell_cache_control always; rewrite ^/config\.json$ /config.json break; rewrite ^/manifest\.json$ /manifest.json break; rewrite ^/sw\.js$ /sw.js break;