rails-index-now 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29bd23e10568ddc7089481dcd364de4a24521ab19dbab5b6c3e32be9d76abc3f
4
- data.tar.gz: fa96fb54b6ec5e07b8ca025fd20d04addafb1f94eeb0a950f44ee35f4821527d
3
+ metadata.gz: a28e088a7240b2bca41a4246f6d6072c2dc73ffc297c2e23b01980699ddd06f6
4
+ data.tar.gz: 7a2b300338c3d8e0cbd5664cd352553e84d050eb4bb796f03f6be0659b9f70a3
5
5
  SHA512:
6
- metadata.gz: c0acabbc857d732648c638c570039330e4d170a78302c2d6e8be00ff1a22c6379e9a38163ebd0d5d7e1609c17946b1cf395f527ea86f385433bf089f45453fde
7
- data.tar.gz: 18945e05c71b28de394f334a87e3a378010a6fdc8654c69912039a708e378b642fd22235a0f4ebe32482ee9c4fd5e62699f75b9814d9532512618e08902936e4
6
+ metadata.gz: 7dfc952ab197e1c9ca298c6e81301aa2f5ec41c1b0fcf177068d2caaacefcc63dfe59f6d13e1088e02d4bc04ed9a0cc6b0d8877ecb02d277d4801c52b9335625
7
+ data.tar.gz: ee2ecfb5a48fe6746b29552c552ea08ea91c8557041e4ab9b4fca07109b2e748f7f01942f709a9c455a7fdb2a1f50abd47bf1ef8a507c66b9610269812ceadf1
data/README.md CHANGED
@@ -21,9 +21,9 @@ Traditional search engine indexing relies on crawlers periodically visiting your
21
21
 
22
22
  ### Why This Rails Engine?
23
23
 
24
- - **🚀 Plug-and-Play**: No manual controller or route setup required
25
- - **🔐 Automatic Verification**: The engine automatically serves your API key file at the correct URL
26
- - **⚡ Zero Configuration**: Just add the gem, run the generator, and you're ready
24
+ - **🚀 Easy Setup**: Pre-built controller and simple route configuration
25
+ - **🔐 Verification Ready**: Built-in controller serves your API key file for IndexNow verification
26
+ - **⚡ Minimal Configuration**: Just add the gem, run generator, add one route, and you're ready
27
27
  - **🛡️ Production Ready**: Built-in error handling, logging, and environment controls
28
28
 
29
29
  ## Installation
@@ -71,10 +71,39 @@ Get your free API key from [Bing IndexNow](https://www.bing.com/indexnow/getstar
71
71
  INDEXNOW_API_KEY=your_api_key_here
72
72
  ```
73
73
 
74
- **That's it!** The engine automatically:
75
- - ✅ Serves your API key at `/your_api_key_here.txt` (for IndexNow verification)
76
- - Handles all routing and controller logic
77
- - ✅ Configures sensible defaults for all environments
74
+ ### 4. Mount the Engine
75
+
76
+ Add this to your `config/routes.rb` file:
77
+
78
+ **Option A: Mount at root (recommended):**
79
+ ```ruby
80
+ Rails.application.routes.draw do
81
+ mount Rails::Index::Now::Engine, at: "/"
82
+
83
+ # ... your other routes
84
+ end
85
+ ```
86
+
87
+ **Option B: Mount at a path (if you have conflicts):**
88
+ ```ruby
89
+ Rails.application.routes.draw do
90
+ mount Rails::Index::Now::Engine, at: "/indexnow"
91
+
92
+ # ... your other routes
93
+ end
94
+ ```
95
+
96
+ **Note:**
97
+ - Option A serves your key at `/your_api_key.txt` (IndexNow standard)
98
+ - Option B serves your key at `/indexnow/your_api_key.txt`
99
+ - The engine only responds to API key files (alphanumeric + hyphens/underscores ending in `.txt`)
100
+ - Files like `/robots.txt`, `/sitemap.txt` are not affected
101
+
102
+ **That's it!** The engine automatically provides:
103
+ - ✅ API key verification at `/your_api_key.txt` (IndexNow requirement)
104
+ - ✅ Built-in controller with comprehensive error handling
105
+ - ✅ Secure validation (only serves configured key file)
106
+ - ✅ Sensible defaults for all environments
78
107
 
79
108
  ### Configuration Options
80
109
 
@@ -204,10 +233,10 @@ This Rails Engine requires:
204
233
  - **Ruby 2.7+**
205
234
  - **ActiveJob** (optional, only needed for `submit_async` functionality)
206
235
 
207
- The engine automatically integrates with your Rails application:
236
+ The engine integrates with your Rails application:
208
237
 
209
- - **🔄 Automatic Routing**: No need to manually add routes - the engine handles it
210
238
  - **🎛️ Controller Integration**: Built-in controller serves API key verification file
239
+ - **🔄 Simple Routing**: One-line route addition to connect IndexNow verification
211
240
  - **⚡ ActiveJob**: Optional - enables `submit_async` method with any backend (Sidekiq, SolidQueue, etc.)
212
241
  - **📝 Smart Logging**: Uses Rails.logger with helpful [IndexNow] prefixes
213
242
  - **🌍 Environment Awareness**: Easy to disable in development/test environments
@@ -9,9 +9,22 @@ module Rails
9
9
 
10
10
  def index_now_key
11
11
  config = Rails::Index::Now.configuration
12
+ requested_file = params[:key_file_name]
12
13
 
13
14
  unless config.engine_valid?
14
- render plain: "IndexNow configuration invalid", status: :internal_server_error
15
+ error_details = []
16
+ error_details << "api_key missing" if config.api_key.nil? || config.api_key.empty?
17
+ error_details << "key_file_name missing" if config.key_file_name.nil? || config.key_file_name.empty?
18
+
19
+ error_message = "IndexNow configuration invalid: #{error_details.join(', ')}"
20
+ Rails.logger.error "[IndexNow] #{error_message}"
21
+ render plain: error_message, status: :internal_server_error
22
+ return
23
+ end
24
+
25
+ # Verify the requested file matches our configured key file
26
+ unless requested_file == config.key_file_name
27
+ head :not_found
15
28
  return
16
29
  end
17
30
 
data/config/routes.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Rails::Index::Now::Engine.routes.draw do
4
- # This route will be dynamically configured based on the key_file_name
5
- # The actual route registration happens in the engine's initialization
4
+ # Only match files that look like API keys (alphanumeric + hyphens/underscores, ending in .txt)
5
+ get "/:key_file_name", to: "verification#index_now_key",
6
+ constraints: { key_file_name: /[a-zA-Z0-9_-]+\.txt/ }
6
7
  end
@@ -4,14 +4,13 @@
4
4
  # See https://github.com/your-username/rails-index-now for full documentation
5
5
 
6
6
  Rails::Index::Now.configure do |config|
7
- # Required: Your IndexNow API key
8
- # You can get one from https://www.bing.com/indexnow/getstarted
9
- config.api_key = ENV.fetch("INDEXNOW_API_KEY", nil)
10
-
11
- # Required: Key file name for IndexNow verification
12
- # This should be "YOUR_API_KEY.txt" (replace YOUR_API_KEY with your actual key)
13
- # The gem will automatically serve this file at /YOUR_API_KEY.txt
14
- config.key_file_name = "#{ENV.fetch("INDEXNOW_API_KEY", "your-api-key")}.txt"
7
+ # The gem automatically reads INDEXNOW_API_KEY from ENV
8
+ # You can override it here if needed:
9
+ # config.api_key = "your-custom-key"
10
+
11
+ # The gem automatically sets key_file_name to "#{ENV['INDEXNOW_API_KEY']}.txt"
12
+ # You can override it here if needed:
13
+ # config.key_file_name = "custom-filename.txt"
15
14
 
16
15
  # Optional: Set a specific host for all submissions
17
16
  # If not set, the gem will extract the host from the submitted URLs
@@ -25,3 +24,15 @@ Rails::Index::Now.configure do |config|
25
24
  # Defaults to Rails.logger if available, otherwise STDOUT
26
25
  # config.logger = Rails.logger
27
26
  end
27
+
28
+ # IMPORTANT: Add this to your config/routes.rb file:
29
+ #
30
+ # Option A (recommended - serves key at /your_api_key.txt):
31
+ # Rails.application.routes.draw do
32
+ # mount Rails::Index::Now::Engine, at: "/"
33
+ # end
34
+ #
35
+ # Option B (if you have routing conflicts):
36
+ # Rails.application.routes.draw do
37
+ # mount Rails::Index::Now::Engine, at: "/indexnow"
38
+ # end
@@ -86,8 +86,8 @@ module Rails
86
86
  end
87
87
 
88
88
  def process_response(response, url_count)
89
- if response.code == "200"
90
- log_info("Successfully submitted #{url_count} URLs to IndexNow")
89
+ if ["200", "202"].include?(response.code)
90
+ log_info("Successfully submitted #{url_count} URLs to IndexNow (#{response.code})")
91
91
  true
92
92
  else
93
93
  log_error("IndexNow API returned #{response.code}: #{response.body}")
@@ -14,6 +14,14 @@ module Rails
14
14
  @key_file_name = nil
15
15
  end
16
16
 
17
+ def api_key
18
+ @api_key || ENV['INDEXNOW_API_KEY']
19
+ end
20
+
21
+ def key_file_name
22
+ @key_file_name || (ENV['INDEXNOW_API_KEY'] ? "#{ENV['INDEXNOW_API_KEY']}.txt" : nil)
23
+ end
24
+
17
25
  def disabled?
18
26
  @disabled
19
27
  end
@@ -12,15 +12,6 @@ module Rails
12
12
  require "generators/index_now/install_generator"
13
13
  end
14
14
 
15
- initializer "rails_index_now.add_routes" do |app|
16
- app.routes.prepend do
17
- config = Rails::Index::Now.configuration
18
- if config.engine_valid?
19
- get "/#{config.key_file_name}",
20
- to: "rails/index/now/verification#index_now_key"
21
- end
22
- end
23
- end
24
15
  end
25
16
  end
26
17
  end
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module Index
5
5
  module Now
6
- VERSION = "0.1.2"
6
+ VERSION = "0.1.4"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-index-now
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleks Ulanov