Caddy가 불변 아티팩트를 직접 제공하고 runtime과 builder의 자원·비밀 경계를 분리한다. Gateway active release ref를 재기동에 복원하고 production/development/smoke 모델 검증을 확장한다.
51 lines
2.0 KiB
JavaScript
51 lines
2.0 KiB
JavaScript
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"/,
|
|
);
|
|
});
|
|
|
|
test('Caddy serves published frontend artifacts directly and keeps a transition fallback', async () => {
|
|
const caddyfile = await fs.readFile(new URL('../caddy/Caddyfile', import.meta.url), 'utf8');
|
|
for (const [profile, port] of Object.entries({
|
|
gateway: 15000,
|
|
che: 15002,
|
|
kwe: 15004,
|
|
pwe: 15006,
|
|
twe: 15008,
|
|
nya: 15010,
|
|
pya: 15012,
|
|
hwe: 15014,
|
|
})) {
|
|
assert.match(caddyfile, new RegExp(`/srv/frontend-artifacts/${profile}/current`));
|
|
assert.match(caddyfile, new RegExp(`reverse_proxy runtime:${port}`));
|
|
assert.match(
|
|
caddyfile,
|
|
new RegExp(`route \\{[\\s\\S]*?@${profile}Asset path /assets/\\*[\\s\\S]*?handle @${profile}Asset`),
|
|
);
|
|
}
|
|
assert.match(caddyfile, /try_files \{path\} \/index\.html/);
|
|
assert.match(caddyfile, /header @frontendRequests Cache-Control "no-cache"/);
|
|
});
|