diff --git a/application.rb b/application.rb index 11df8a7..a150cd6 100644 --- a/application.rb +++ b/application.rb @@ -3,6 +3,7 @@ require 'sinatra' require './lib/partials' require './lib/string' +require './lib/constants' require 'haml' require 'sass' require 'compass' @@ -42,6 +43,18 @@ scss :'stylesheets/screen' end +# Show lib/robots_txt_to_exclude_all.txt +# +# Only show on non-production sites +get '/robots.txt' do + if is_production? + redirect not_found + else + content_type 'text/plain', :charset => 'utf-8' + File.read(File.join('lib', 'robots_txt_to_exclude_all.txt')) + end +end + get '/' do protected_unless_disabled! diff --git a/lib/constants.rb b/lib/constants.rb new file mode 100644 index 0000000..e57c3fe --- /dev/null +++ b/lib/constants.rb @@ -0,0 +1,7 @@ +# Constants + +HTTP_STATUS_OK = 200 +HTTP_STATUS_BAD_REQUEST = 400 +HTTP_STATUS_NOT_FOUND = 404 +HTTP_STATUS_BAD_REQUEST_CONFLICT = 409 +HTTP_STATUS_INTERNAL_SERVER_ERROR = 500 \ No newline at end of file diff --git a/lib/robots_txt_to_exclude_all.txt b/lib/robots_txt_to_exclude_all.txt new file mode 100644 index 0000000..77470cb --- /dev/null +++ b/lib/robots_txt_to_exclude_all.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / \ No newline at end of file diff --git a/spec/integration/robots_txt_spec.rb b/spec/integration/robots_txt_spec.rb new file mode 100644 index 0000000..718100a --- /dev/null +++ b/spec/integration/robots_txt_spec.rb @@ -0,0 +1,23 @@ +require_relative '../spec_helper' + +describe "/robots.txt" do + before { @robots_path = "/robots.txt" } + + it "shows on development" do + settings.environment = "development" + get @robots_path + expect(last_response.status).to be HTTP_STATUS_OK + end + + it "shows on staging" do + settings.environment = "staging" + get @robots_path + expect(last_response.status).to be HTTP_STATUS_OK + end + + it "doesn't show in production" do + settings.environment = "production" + get @robots_path + expect(last_response.status).to be HTTP_STATUS_NOT_FOUND + end +end \ No newline at end of file