Skip to content

fix: add unmapped surrogate key for 404.html #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/steps/fetch-404.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,19 @@ export default async function fetch404(state, req, res) {

// set 404 keys in any case
const pathKey = await getPathKey(state);
res.headers.set('x-surrogate-key', `${pathKey} ${contentBusId} ${ref}--${repo}--${owner}_404 ${ref}--${repo}--${owner}_code`);
const keys = [
pathKey,
contentBusId,
`${ref}--${repo}--${owner}_404`,
`${ref}--${repo}--${owner}_code`,
];

if (state.info.unmappedPath) {
keys.push(await getPathKey({
contentBusId,
info: { path: state.info.unmappedPath },
}));
}

res.headers.set('x-surrogate-key', keys.join(' '));
}
13 changes: 13 additions & 0 deletions test/rendering.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const DEFAULT_CONFIG = {
'/products': '/generic-product',
'/articles/': '/special/default-article',
'/app': '/spa/index.html',
'/broken': '/not-a-page',
},
headers: HEADERS,
metadata: {
Expand Down Expand Up @@ -527,6 +528,18 @@ describe('Rendering', () => {
assert.strictEqual(body.trim(), '');
});

it('renders 404 for folder mapped not found', async () => {
const { headers, body } = await testRender(new URL('https://helix-pipeline.com/broken/folder'), 'html', 404);
assert.deepStrictEqual(Object.fromEntries(headers.entries()), {
'access-control-allow-origin': '*',
'content-type': 'text/html; charset=utf-8',
link: '</scripts/scripts.js>; rel=modulepreload; as=script; crossorigin=use-credentials',
'x-error': 'failed to load /not-a-page.md from content-bus: 404',
'x-surrogate-key': 'gPHXKWdMY_R8KV2Z foo-id super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code QJqsV4atnOA47sHc',
});
assert.strictEqual(body.trim(), '');
});

it('renders 301 for redirect file', async () => {
loader.headers('one-section.md', 'x-amz-meta-redirect-location', 'https://www.adobe.com');
const ret = await render(new URL('https://localhost/one-section'), '', 301);
Expand Down