Skip to content

Instantly share code, notes, and snippets.

@zkan
Created August 1, 2017 02:23
Show Gist options
  • Save zkan/a04af236c7254e6e34605a1b8e7b6b2f to your computer and use it in GitHub Desktop.
Save zkan/a04af236c7254e6e34605a1b8e7b6b2f to your computer and use it in GitHub Desktop.
HTTP Basic Authentication for Jekyll on Heroku
require 'rack/jekyll'
require "rack/rewrite"
use Rack::Auth::Basic, "Restricted Area" do |username, password|
[username, password] == ['admin', 'admin'] or [username, password] == ['zkan', '123'] or [username, password] == ['cory', 'cool']
end
use Rack::Rewrite do
rewrite %r{/(.+)}, lambda { |match, rack_env|
if File.exists?('_site/' + match[1] + '.html')
return '/' + match[1] + '.html'
else
return '/' + match[1]
end
}
end
run Rack::Jekyll.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment