Created
August 1, 2017 02:23
-
-
Save zkan/a04af236c7254e6e34605a1b8e7b6b2f to your computer and use it in GitHub Desktop.
HTTP Basic Authentication for Jekyll on Heroku
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/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