I've just tried add this wrapper (-> routes (wrap-ssl-redirect))
for auto redirecting http to https, but when I deploy to heroku, the https://
doesn't get green in my browser, and the website doesn't load.
Isn't the default heroku port 443
, which should also be the default from wrap-ssl-redirect
function?
What is wrong?
Thank you!
EDIT:
My code:
(defn prod-app [routes]
(-> routes
(wrap-keyword-params)
(wrap-params)
(wrap-ssl-redirect)))
(defn -main []
(let [port (Integer/parseInt (get (System/getenv) "PORT" "5000"))]
(jetty/run-jetty (prod-app domain-specific-routes)
{:port port :join? false})))
EDIT 2:
I just found this thread which could solve my problem: Clojure / Noir: Force HTTPS, redirect if the request was http:// to https://
Came up with this require-https
handler fn:
(defn https-url [request-url]
(str "https://"
(:server-name request-url)
":"
(:server-port request-url)
(:uri request-url)))
(defn require-https
[handler]
(fn [request]
(if (and (= (:scheme request) :http)
(= (get-in request [:headers "host"]) "secure.mydomain.com"))
(ring.util.response/redirect (https-url request))
(handler request))))
But when I try to connect to http://secure.mydomain.com
, I am seing a port in the browser address bar https://secure.mydomain.com:80/
and got this message ERR_SSL_PROTOCOL_ERROR
.