From 013c463d5adac2efbdf96855c40015c4165f7b37 Mon Sep 17 00:00:00 2001 From: Aaron Moore Date: Thu, 23 Jan 2025 10:00:41 +0000 Subject: [PATCH] WSTEAM1-1612 - Set `noindex` on av-embeds pages --- .../pages/[service]/av-embeds/handleAvRoute.test.ts | 9 +++++++++ .../pages/[service]/av-embeds/handleAvRoute.ts | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.test.ts b/ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.test.ts index eea5af4d322..264e82e746d 100644 --- a/ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.test.ts +++ b/ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.test.ts @@ -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); diff --git a/ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.ts b/ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.ts index 3850703996f..6c829579c40 100644 --- a/ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.ts +++ b/ws-nextjs-app/pages/[service]/av-embeds/handleAvRoute.ts @@ -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,