Skip to content

Commit f33634a

Browse files
fix: surrogate key for static html
1 parent 32ddfc0 commit f33634a

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/steps/set-x-surrogate-key-header.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,20 @@ export default async function setXSurrogateKeyHeader(state, req, res) {
4444
const {
4545
contentBusId, owner, repo, ref,
4646
} = state;
47-
const hash = await getPathKey(state);
48-
const keys = [
49-
hash,
50-
`${contentBusId}_metadata`,
51-
`${ref}--${repo}--${owner}_head`,
52-
contentBusId,
53-
];
5447

48+
const isCode = state.content.sourceBus === 'code';
49+
50+
const keys = [];
51+
const hash = await getPathKey(state);
52+
if (isCode) {
53+
keys.push(await computeSurrogateKey(`${ref}--${repo}--${owner}${state.info.path}`));
54+
keys.push(`${ref}--${repo}--${owner}_code`);
55+
} else {
56+
keys.push(hash);
57+
keys.push(`${contentBusId}_metadata`);
58+
keys.push(`${ref}--${repo}--${owner}_head`);
59+
keys.push(contentBusId);
60+
}
5561
// for folder-mapped resources, we also need to include the surrogate key of the mapped metadata
5662
if (state.mapped) {
5763
keys.push(`${hash}_metadata`);

test/html-pipe.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ describe('HTML Pipe Test', () => {
221221
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
222222
'content-type': 'text/html; charset=utf-8',
223223
'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT',
224-
'x-surrogate-key': 'kvcvppnfHtt5omSX foo-id_metadata super-test--helix-pages--adobe_head foo-id',
224+
'x-surrogate-key': 'oAJVhwwmjc53GpIM super-test--helix-pages--adobe_code',
225225
});
226226
});
227227
});

test/rendering.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ describe('Rendering', () => {
620620
'access-control-allow-origin': '*',
621621
'content-type': 'text/html; charset=utf-8',
622622
'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT',
623-
'x-surrogate-key': 'SUhNxkR2spoxY489 foo-id_metadata super-test--helix-pages--adobe_head foo-id',
623+
'x-surrogate-key': 'OjUJ-F2DzRC3rMht super-test--helix-pages--adobe_code',
624624
link: '</scripts/scripts.js>; rel=modulepreload; as=script; crossorigin=use-credentials',
625625
});
626626
});
@@ -673,7 +673,7 @@ describe('Rendering', () => {
673673
'access-control-allow-origin': '*',
674674
'content-type': 'text/html; charset=utf-8',
675675
'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT',
676-
'x-surrogate-key': 'VmeAc3K7QsCRzj5Z foo-id_metadata super-test--helix-pages--adobe_head foo-id',
676+
'x-surrogate-key': 'OhRDjcpvIRqjAeih super-test--helix-pages--adobe_code',
677677
link: '</scripts/scripts.js>; rel=modulepreload; as=script; crossorigin=use-credentials',
678678
});
679679
});

0 commit comments

Comments
 (0)