Class: Rails::Index::Now::VerificationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/rails/index/now/verification_controller.rb

Instance Method Summary collapse

Instance Method Details

#index_now_keyObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/rails/index/now/verification_controller.rb', line 10

def index_now_key
  config = Rails::Index::Now.configuration
  requested_file = params[:key_file_name]

  unless config.engine_valid?
    error_details = []
    error_details << "api_key missing" if config.api_key.nil? || config.api_key.empty?
    error_details << "key_file_name missing" if config.key_file_name.nil? || config.key_file_name.empty?
    
    error_message = "IndexNow configuration invalid: #{error_details.join(', ')}"
    Rails.logger.error "[IndexNow] #{error_message}"
    render plain: error_message, status: :internal_server_error
    return
  end

  # Verify the requested file matches our configured key file
  unless requested_file == config.key_file_name
    head :not_found
    return
  end

  render plain: config.api_key, content_type: "text/plain"
end