From 59a13700bea222fcb88f208178390694acf31682 Mon Sep 17 00:00:00 2001 From: Christophe Jossart Date: Thu, 28 Nov 2024 19:46:05 +0100 Subject: [PATCH 1/3] chore(SLB-478): drupal noindex --- packages/drupal/custom/custom.services.yml | 5 +++ .../src/EventSubscriber/RobotsSubscriber.php | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 packages/drupal/custom/src/EventSubscriber/RobotsSubscriber.php diff --git a/packages/drupal/custom/custom.services.yml b/packages/drupal/custom/custom.services.yml index 7424d6f1d..74980bc9f 100644 --- a/packages/drupal/custom/custom.services.yml +++ b/packages/drupal/custom/custom.services.yml @@ -16,3 +16,8 @@ services: arguments: ['@language_manager', '@current_route_match'] tags: - { name: event_subscriber } + + custom.event_subscriber: + class: Drupal\custom\EventSubscriber\RobotsSubscriber + tags: + - { name: event_subscriber } diff --git a/packages/drupal/custom/src/EventSubscriber/RobotsSubscriber.php b/packages/drupal/custom/src/EventSubscriber/RobotsSubscriber.php new file mode 100644 index 000000000..cc9550f3a --- /dev/null +++ b/packages/drupal/custom/src/EventSubscriber/RobotsSubscriber.php @@ -0,0 +1,36 @@ +getResponse(); + $response->headers->set('X-Robots-Tag', 'noindex, nofollow'); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents(): array { + return [ + KernelEvents::RESPONSE => ['onKernelResponse'], + ]; + } + +} From d330e5bbeaa7f8121e6f274c24441cef7abe2d4b Mon Sep 17 00:00:00 2001 From: Christophe Jossart Date: Thu, 28 Nov 2024 20:08:52 +0100 Subject: [PATCH 2/3] chore(SLB-478): gatsby noindex --- apps/website/gatsby-config.mjs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/website/gatsby-config.mjs b/apps/website/gatsby-config.mjs index 81457209e..cd6f4c782 100644 --- a/apps/website/gatsby-config.mjs +++ b/apps/website/gatsby-config.mjs @@ -12,6 +12,8 @@ process.env.CLOUDINARY_API_KEY = process.env.CLOUDINARY_API_KEY || 'test'; process.env.CLOUDINARY_API_SECRET = process.env.CLOUDINARY_API_SECRET || 'test'; process.env.CLOUDINARY_CLOUDNAME = process.env.CLOUDINARY_CLOUDNAME || 'demo'; +process.env.NOINDEX = process.env.NOINDEX || 'false'; + /** * * @type {import('gatsby').GatsbyConfig['plugins']} @@ -42,6 +44,12 @@ const plugins = [ options: { // To avoid "X-Frame-Options: DENY" in Drupal iframes. mergeSecurityHeaders: false, + headers: + process.env.NOINDEX === 'true' + ? { + '/*': ['X-Robots-Tag: noindex, nofollow'], + } + : {}, }, }, { @@ -50,7 +58,10 @@ const plugins = [ { resolve: 'gatsby-plugin-robots-txt', options: { - policy: [{ userAgent: '*', allow: '/', disallow: [] }], + policy: + process.env.NOINDEX === 'true' + ? [{ userAgent: '*', disallow: '/' }] + : [{ userAgent: '*', allow: '/', disallow: [] }], }, }, { From d79168a587a2575812226c12cf9ac2eaa234e557 Mon Sep 17 00:00:00 2001 From: Christophe Jossart Date: Fri, 29 Nov 2024 15:47:31 +0100 Subject: [PATCH 3/3] chore(SLB-478): preview noindex --- apps/preview/server/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/preview/server/index.ts b/apps/preview/server/index.ts index 2b0bd880a..3e1109b2f 100644 --- a/apps/preview/server/index.ts +++ b/apps/preview/server/index.ts @@ -32,6 +32,12 @@ if (isSessionRequired()) { // Authentication middleware based on the configuration. const authMiddleware = getAuthenticationMiddleware(); +// Prevent indexing. +app.use((_, res, next) => { + res.setHeader('X-Robots-Tag', 'noindex, nofollow'); + next(); +}); + app.get('/endpoint.js', (_, res) => { res.send( `window.GRAPHQL_ENDPOINT = "${