Created
May 8, 2016 20:42
-
-
Save matthewlehner/2dc7377c4207297ea628632cf0616256 to your computer and use it in GitHub Desktop.
This file contains 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
class LetsEncryptResponse | |
ACME_ENDPOINT_REGEX = /\A\/\.well-known\/acme-challenge\/(?<challenge>.*)\z/ | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new env | |
if request.path.start_with?("/.well-known/acme-challenge/") | |
match = request.path.match ACME_ENDPOINT_REGEX | |
challenge = match[:challenge] | |
if ENV["ACME_CHALLENGE"] && ENV["ACME_RESPONSE"] && challenge == ENV["ACME_CHALLENGE"] | |
[200, { "Content-Type" => "text/plain" }, [ENV["ACME_RESPONSE"]]] | |
else | |
[400, {}, ["This is a horrible error message."]] | |
end | |
else | |
@app.call env | |
end | |
end | |
end | |
Rails.config.middleware.insert_before ActionDispatch::SSL, LetsEncryptResponse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment