Add robots meta tags and headers, to prevent search engine indexing [SCI-12447]

This commit is contained in:
Martin Artnik 2025-10-09 09:39:15 +02:00
parent 963a3b4959
commit c19e414b18
5 changed files with 25 additions and 0 deletions

View file

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow">
<%= csp_meta_tag %>
<meta data-hook="head-js">
<title><%=t "head.title", title: (yield :head_title) %></title>

View file

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow">
<%= csp_meta_tag %>
<meta data-hook="head-js">
<title><%=t "head.title", title: (yield :head_title) %></title>

View file

@ -3,6 +3,7 @@
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow">
<%= csp_meta_tag %>
<meta data-hook="head-js">
<title><%=t "head.title", title: (yield :head_title) %></title>

View file

@ -15,6 +15,8 @@ require 'action_view/railtie'
# require "rails/test_unit/railtie"
require 'datadog/auto_instrument' if ENV['DD_TRACE_ENABLED'] == 'true'
require_relative '../lib/rack_x_robots_tag'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
@ -58,6 +60,9 @@ module Scinote
# Add rack-attack middleware for request rate limiting
config.middleware.use Rack::Attack
# Add X-Robots-Tag header to all responses, to prevent search engine indexing
config.middleware.use Rack::XRobotsTag
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
config.encoding = 'utf-8'

17
lib/rack_x_robots_tag.rb Normal file
View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Rack
class XRobotsTag
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
headers['X-Robots-Tag'] = 'none'
[status, headers, response]
end
end
end