perf(caddy): 해시 빌드 자산에 장기 캐시를 적용

Vite content hash가 포함된 frontend asset만 1년 immutable로 제공한다. HTML, hash 없는 asset과 별도 image 경로는 기존 재검증 정책을 유지하고 matcher 회귀 테스트와 운영 문서를 추가한다.
This commit is contained in:
2026-08-18 12:55:07 +00:00
parent 08bd24909e
commit 7af9c88c27
3 changed files with 55 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
test('Caddy caches only content-hashed Vite frontend assets as immutable', async () => {
const caddyfile = await fs.readFile(new URL('../caddy/Caddyfile', import.meta.url), 'utf8');
const matcher = caddyfile.match(
/@immutableFrontendAssets path_regexp immutableFrontendAssets (\S+)/,
);
assert.ok(matcher, 'immutable frontend asset matcher must exist');
const assetPath = new RegExp(matcher[1]);
for (const profile of ['gateway', 'che', 'kwe', 'pwe', 'twe', 'nya', 'pya', 'hwe']) {
assert.equal(assetPath.test(`/${profile}/assets/index-CcXtLSVk.js`), true);
assert.equal(assetPath.test(`/${profile}/assets/index-CcXtLSVk.js.map`), true);
}
assert.equal(assetPath.test('/gateway/'), false);
assert.equal(assetPath.test('/gateway/terms.1.html'), false);
assert.equal(assetPath.test('/gateway/assets/index.js'), false);
assert.equal(assetPath.test('/image/game/figure.png'), false);
assert.match(
caddyfile,
/header @immutableFrontendAssets >Cache-Control "public, max-age=31536000, immutable"/,
);
});