-
-
Save ivan-leschinsky/89fe44b11aa34ace1406 to your computer and use it in GitHub Desktop.
Middleware for robots.txt disallowing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Disallow site indexing in non-production environments | |
| config.middleware.insert_before(::Rack::Lock, '::Rack::Robots') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rack' | |
| # Disallow site indexing in non-production environments | |
| module Rack | |
| class Robots | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) | |
| if env['PATH_INFO'] == '/robots.txt' && !([ENV['RAILS_ENV'], ENV['RACK_ENV']].include? 'production') | |
| [200, { 'Content-Type' => 'text/plain' }, ["User-Agent: *\nDisallow: /"]] | |
| else | |
| @app.call env | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Disallow site indexing in non-production environments | |
| Rails.application.config.middleware.insert_before(::Rack::Lock, '::Rack::Robots') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
brentertz says: