Skip to content

Commit 8d36aa2

Browse files
authored
fix: add unmapped surrogate key for 404.html (#633)
fixes #632
1 parent 86f1787 commit 8d36aa2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/steps/fetch-404.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,19 @@ export default async function fetch404(state, req, res) {
4040

4141
// set 404 keys in any case
4242
const pathKey = await getPathKey(state);
43-
res.headers.set('x-surrogate-key', `${pathKey} ${contentBusId} ${ref}--${repo}--${owner}_404 ${ref}--${repo}--${owner}_code`);
43+
const keys = [
44+
pathKey,
45+
contentBusId,
46+
`${ref}--${repo}--${owner}_404`,
47+
`${ref}--${repo}--${owner}_code`,
48+
];
49+
50+
if (state.info.unmappedPath) {
51+
keys.push(await getPathKey({
52+
contentBusId,
53+
info: { path: state.info.unmappedPath },
54+
}));
55+
}
56+
57+
res.headers.set('x-surrogate-key', keys.join(' '));
4458
}

test/rendering.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const DEFAULT_CONFIG = {
120120
'/products': '/generic-product',
121121
'/articles/': '/special/default-article',
122122
'/app': '/spa/index.html',
123+
'/broken': '/not-a-page',
123124
},
124125
headers: HEADERS,
125126
metadata: {
@@ -527,6 +528,18 @@ describe('Rendering', () => {
527528
assert.strictEqual(body.trim(), '');
528529
});
529530

531+
it('renders 404 for folder mapped not found', async () => {
532+
const { headers, body } = await testRender(new URL('https://helix-pipeline.com/broken/folder'), 'html', 404);
533+
assert.deepStrictEqual(Object.fromEntries(headers.entries()), {
534+
'access-control-allow-origin': '*',
535+
'content-type': 'text/html; charset=utf-8',
536+
link: '</scripts/scripts.js>; rel=modulepreload; as=script; crossorigin=use-credentials',
537+
'x-error': 'failed to load /not-a-page.md from content-bus: 404',
538+
'x-surrogate-key': 'gPHXKWdMY_R8KV2Z foo-id super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code QJqsV4atnOA47sHc',
539+
});
540+
assert.strictEqual(body.trim(), '');
541+
});
542+
530543
it('renders 301 for redirect file', async () => {
531544
loader.headers('one-section.md', 'x-amz-meta-redirect-location', 'https://www.adobe.com');
532545
const ret = await render(new URL('https://localhost/one-section'), '', 301);

0 commit comments

Comments
 (0)