From c41805adc265c5b92d5d3ddd8c2f16fb3cb78717 Mon Sep 17 00:00:00 2001 From: awb99 Date: Wed, 8 Jan 2025 17:25:21 -0500 Subject: [PATCH] bugfix response --- demo/src/demo/https.clj | 3 +- src/modular/webserver/https/letsencrypt.clj | 2 ++ src/modular/webserver/https/proxy.clj | 33 +++++++++------------ 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/demo/src/demo/https.clj b/demo/src/demo/https.clj index 9ba2aad..7692929 100644 --- a/demo/src/demo/https.clj +++ b/demo/src/demo/https.clj @@ -10,8 +10,7 @@ (defn main-page [_] (page {:title "demo-123" - :author "goblin77" - } + :author "goblin77"} [:div [:h1 "hello, world!"] [:a {:href "/r/demo.txt"} [:p "demo.txt"]] diff --git a/src/modular/webserver/https/letsencrypt.clj b/src/modular/webserver/https/letsencrypt.clj index f37d07a..e965b21 100644 --- a/src/modular/webserver/https/letsencrypt.clj +++ b/src/modular/webserver/https/letsencrypt.clj @@ -16,6 +16,8 @@ (assert domain "domain needs to be a string and a valid domain (www.demo.com)") (assert email "email needs to be a string and a valid email (webmaster@demo.com)") ; certbot either needs to run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths. + ; When using the webroot method the Certbot client places a challenge response inside domain.com/.well-known/acme-challenge/ + ; which is used for validation. When validation is complete, challenge file is removed from the target directory (shell "certbot" "certonly" "--non-interactive" "--agree-tos" "-m" email diff --git a/src/modular/webserver/https/proxy.clj b/src/modular/webserver/https/proxy.clj index 45103a8..4bf21d1 100644 --- a/src/modular/webserver/https/proxy.clj +++ b/src/modular/webserver/https/proxy.clj @@ -5,14 +5,13 @@ [ring.util.response :as response] [reitit.ring :as ring] [ring.adapter.jetty :refer [run-jetty]] - [modular.webserver.https.letsencrypt :refer [renew-cert convert-cert]] - )) + [modular.webserver.https.letsencrypt :refer [renew-cert convert-cert]])) (defn redirect-handler [port] (fn [{:keys [uri server-name scheme query-string] :as req}] - (info"redirecting request: " uri) - (let [redirect-url (str scheme "://" server-name ":" port uri (when query-string (str "?" query-string)))] - (response/redirect redirect-url)))) + (info "redirecting request: " uri) + (let [redirect-url (str scheme "://" server-name ":" port uri (when query-string (str "?" query-string)))] + (response/redirect redirect-url)))) (defn static-file-handler [path] (let [acme-dir (str path "/.well-known/acme-challenge") @@ -26,22 +25,18 @@ (fn [_req] (info "certificate-get started..") (let [r (renew-cert letsencrypt)] - (info "result: " r) - (response/response {:body "certificate-get started!"})))) + (info "result: " r) + (response/response "certificate-get started!")))) (defn certificate-import-handler [{:keys [letsencrypt https] :as config}] (fn [_req] - (info "certificate-convert started..") + (info "certificate-convert started..") (let [r (convert-cert letsencrypt https)] (info "result: " r) - (response/response {:body "certificate-import started!"}))) - ) - - - + (response/response "certificate-import started!")))) -(defn start-proxy - "http server on port 80 that redirects all traffic to 443, except +(defn start-proxy + "http server on port 80 that redirects all traffic to 443, except /.well-known/acme-challenge (which is serves static files for certbot) and /.well-known/ping which will show pong (useful for debugging)" [{:keys [letsencrypt https] @@ -58,9 +53,9 @@ ["*" (redirect-handler 443)]] {:conflicts (constantly nil)}) (ring/create-default-handler))] - (info "redirecting http(80) -> https (443), letsencrypt public: " public-dir) - (run-jetty handler {:port 80 - :allow-null-path-info true ; omit the trailing slash from your URLs - }))) + (info "redirecting http(80) -> https (443), letsencrypt public: " public-dir) + (run-jetty handler {:port 80 + :allow-null-path-info true ; omit the trailing slash from your URLs + })))