Skip to content

fix: contentbus-id as surrogate key for 404 response #629

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 21, 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
6 changes: 4 additions & 2 deletions src/steps/fetch-404.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import { getPathKey } from './set-x-surrogate-key-header.js';
* @returns {Promise<void>}
*/
export default async function fetch404(state, req, res) {
const { owner, repo, ref } = state;
const {
owner, repo, ref, contentBusId,
} = state;
const ret = await state.s3Loader.getObject('helix-code-bus', `${owner}/${repo}/${ref}/404.html`);
if (ret.status === 200) {
// override last-modified if source-last-modified is set
Expand All @@ -38,5 +40,5 @@ 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} ${ref}--${repo}--${owner}_404 ${ref}--${repo}--${owner}_code`);
res.headers.set('x-surrogate-key', `${pathKey} ${contentBusId} ${ref}--${repo}--${owner}_404 ${ref}--${repo}--${owner}_code`);
}
8 changes: 4 additions & 4 deletions test/rendering.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ describe('Rendering', () => {
assert.deepStrictEqual(Object.fromEntries(headers.entries()), {
'content-type': 'text/html; charset=utf-8',
'last-modified': 'Wed, 12 Oct 2009 17:50:00 GMT',
'x-surrogate-key': 'OYsA_wfqip5EuBu6 super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code',
'x-surrogate-key': 'OYsA_wfqip5EuBu6 foo-id super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code',
'x-error': 'failed to load /not-found-with-handler.md from content-bus: 404',
'access-control-allow-origin': '*',
link: '</scripts/scripts.js>; rel=modulepreload; as=script; crossorigin=use-credentials',
Expand All @@ -490,7 +490,7 @@ describe('Rendering', () => {
assert.deepStrictEqual(Object.fromEntries(headers.entries()), {
'content-type': 'text/html; charset=utf-8',
'last-modified': 'Wed, 12 Oct 2009 17:50:00 GMT',
'x-surrogate-key': 'OYsA_wfqip5EuBu6 super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code',
'x-surrogate-key': 'OYsA_wfqip5EuBu6 foo-id super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code',
'x-error': 'failed to load /not-found-with-handler.md from content-bus: 404',
'access-control-allow-origin': '*',
});
Expand All @@ -506,7 +506,7 @@ describe('Rendering', () => {
'content-type': 'text/html; charset=utf-8',
'last-modified': 'Wed, 12 Oct 2009 17:50:00 GMT',
'x-error': 'failed to load /not-found-with-handler.html from code-bus: 404',
'x-surrogate-key': 'ta3V7wR3zlRh1b0E super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code',
'x-surrogate-key': 'ta3V7wR3zlRh1b0E foo-id super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code',
link: '</scripts/scripts.js>; rel=modulepreload; as=script; crossorigin=use-credentials',
'access-control-allow-origin': '*',
});
Expand All @@ -522,7 +522,7 @@ describe('Rendering', () => {
'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT',
link: '</scripts/scripts.js>; rel=modulepreload; as=script; crossorigin=use-credentials',
'x-error': 'request to /index.md not allowed (no-index).',
'x-surrogate-key': 'FzT3jXtDSYMYOTq1 super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code',
'x-surrogate-key': 'FzT3jXtDSYMYOTq1 foo-id super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code',
});
assert.strictEqual(body.trim(), '');
});
Expand Down