Skip to content

Commit

Permalink
WSTEAM1-1612 - Set noindex on av-embeds pages
Browse files Browse the repository at this point in the history
  • Loading branch information
amoore108 committed Jan 23, 2025
1 parent 97de1df commit 013c463
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ describe('Handle AV Route', () => {
});
});

it('should set the x-robots-tag header to noindex', async () => {
await handleAvRoute(mockGetServerSidePropsContext);

expect(mockGetServerSidePropsContext.res.setHeader).toHaveBeenCalledWith(
'x-robots-tag',
'noindex',
);
});

it('should remove the x-frame-options header', async () => {
await handleAvRoute(mockGetServerSidePropsContext);

Expand Down
11 changes: 7 additions & 4 deletions ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ export default async (context: GetServerSidePropsContext) => {
let pageStatus;
let pageJson;

// Remove x-frame-options header to allow embedding
context.res.removeHeader('x-frame-options');

const parsedRoute = parseAvRoute(resolvedUrl);
// Set x-robots-tag header to prevent search engine indexing
context.res.setHeader('x-robots-tag', 'noindex');

context.res.setHeader(
'Cache-Control',
'public, stale-if-error=90, stale-while-revalidate=30, max-age=30',
);

// Remove x-frame-options header to allow embedding
context.res.removeHeader('x-frame-options');

const parsedRoute = parseAvRoute(resolvedUrl);

const avEmbedsUrl = constructPageFetchUrl({
pageType: AV_EMBEDS,
pathname: resolvedUrl,
Expand Down

0 comments on commit 013c463

Please sign in to comment.