Skip to content

Instantly share code, notes, and snippets.

@alexgaribay
Created January 31, 2019 15:25
Show Gist options
  • Save alexgaribay/12e764ebfc51f12101eb01d5776878f2 to your computer and use it in GitHub Desktop.
Save alexgaribay/12e764ebfc51f12101eb01d5776878f2 to your computer and use it in GitHub Desktop.
defmodule MyAppWeb.AcmeChallengeController do
@moduledoc """
Controller used for cerbot renewal.
This module reads a file's contents and provides a value back for domain validation.
With this module you'll need to add a new route to the router.
# router.ex
scope "/.well-known/acme-challenge", ProgressPlumWeb do
get "/:challenge", AcmeChallengeController, :show
end
"""
use MyAppWeb, :controller
def show(conn, %{"challenge" => file_name}) do
base_path = System.get_env("ACME_CHALLENGE_DIR")
safe_file_name = Path.basename(file_name)
case File.read(Path.join([base_path, "/.well-known/acme-challenge", safe_file_name])) do
{:ok, content} ->
send_resp(conn, 200, content)
_ ->
send_resp(conn, 200, "Not Valid")
end
end
def show(conn, _) do
send_resp(conn, 200, "Not Valid")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment