Skip to content

Commit

Permalink
bugfix response
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Jan 8, 2025
1 parent 62f4d0b commit c41805a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
3 changes: 1 addition & 2 deletions demo/src/demo/https.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
2 changes: 2 additions & 0 deletions src/modular/webserver/https/letsencrypt.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 14 additions & 19 deletions src/modular/webserver/https/proxy.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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]
Expand All @@ -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
})))


0 comments on commit c41805a

Please sign in to comment.