diff --git a/nginx.conf b/nginx.conf index 0330446..677f393 100644 --- a/nginx.conf +++ b/nginx.conf @@ -26,6 +26,8 @@ server { audio/mpeg mp3; image/svg+xml svg; image/x-icon ico; + image/jpeg jpg jpeg; + video/mp4 mp4; font/woff2 woff2; } @@ -37,7 +39,7 @@ server { location ~* \.(css|js|mjs|json)$ { add_header Cache-Control "no-cache"; } - location ~* \.(png|webp|mp3|woff2)$ { + location ~* \.(png|webp|jpg|mp3|mp4|woff2|ico)$ { add_header Cache-Control $media_cache; } location = /index.html { diff --git a/tests/story.test.mjs b/tests/story.test.mjs index e1a2914..e56999d 100644 --- a/tests/story.test.mjs +++ b/tests/story.test.mjs @@ -619,6 +619,19 @@ test('ogni cartella di assets usata dal gioco finisce nell\'immagine Docker', as for (const t of Object.values(story.tutorials)) for (const f of [t.src, t.poster]) assert.ok(existsSync(new URL(f, root)), f); }); +// La foto del palio e i video arrivavano al browser come application/octet-stream (26 ottobre): ogni estensione +// servita deve avere il suo tipo in nginx.conf, sennò nginx (con i soli tipi dichiarati) non sa cos'è. +test('ogni estensione dei file serviti ha il suo tipo MIME in nginx.conf', async () => { + const { readdirSync } = await import('node:fs'); + const root = new URL('../', import.meta.url); + const types = readFileSync(new URL('nginx.conf', root), 'utf8').match(/types \{([^}]*)\}/)[1]; + const known = new Set(types.split(';').flatMap(l => l.trim().split(/\s+/).slice(1))); + const dirs = readFileSync(new URL('Dockerfile', root), 'utf8').match(/^COPY (assets\/\S+|src)\s/gm).map(l => l.split(' ')[1]); + const ext = new Set(['html', 'css']); + for (const d of dirs) for (const f of readdirSync(new URL(d + '/', root), { recursive: true })) if (/\.\w+$/.test(f)) ext.add(f.split('.').pop()); + assert.deepEqual([...ext].filter(e => !known.has(e) && e !== 'txt').sort(), [], 'estensioni senza tipo in nginx.conf'); +}); + test('i file che il Docker copia sono leggibili da tutti (nginx gira con un altro utente)', async () => { const { readdirSync, statSync } = await import('node:fs'); const root = new URL('../', import.meta.url);