rails-index-now 0.1.2 → 0.1.3
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 +4 -4
- data/README.md +38 -9
- data/app/controllers/rails/index/now/verification_controller.rb +14 -1
- data/config/routes.rb +3 -2
- data/lib/generators/index_now/templates/index_now.rb +19 -8
- data/lib/rails/index/now/configuration.rb +8 -0
- data/lib/rails/index/now/railtie.rb +0 -9
- data/lib/rails/index/now/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f4ebc6b253eb75e25606e41f2a661f4b7c0feadcc415ce1d0ce84335862b0e6
|
4
|
+
data.tar.gz: c89f6d08b34d3a909a83af7140285c0d5263370c324d4d804d780e9471e92967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9cd737b9adf990105a53e8501392db8ccbffdf493fa925a630cf88a2ef3b41eeca675246d67994dbf790670f69c1d830afa9fd4a41aac0c494c7e4c04e6ece9
|
7
|
+
data.tar.gz: fb9c04d7bea5bedfd4bc7967b59de4e426fb197340cfe6951a945ea263450ac94bfd7b1ab37cb9ddb3ec11e0bee48704209f9d1bcafe6ab967eb5156af28b8e1
|
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
|
-
- **🚀
|
25
|
-
- **🔐
|
26
|
-
- **⚡
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
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
|
-
|
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
|
-
#
|
5
|
-
|
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
|
-
#
|
8
|
-
# You can
|
9
|
-
config.api_key =
|
10
|
-
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
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
|
@@ -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
|