Skip to content

Commit

Permalink
add :use-ssl sugar for setting up ssl support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce Hauman committed Jun 15, 2020
1 parent d0dd5cf commit 962524b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/figwheel/main.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ classpath. Classpath-relative paths have prefix of @ or @/")
(apply io/file)
(.getPath)))

(defn auto-bundle [{:keys [options ::config] :as cfg}]
(defn config-auto-bundle [{:keys [options ::config] :as cfg}]
;; we only support webpack right now
(if (:auto-bundle config)
(cond-> cfg
Expand Down Expand Up @@ -986,6 +986,18 @@ classpath. Classpath-relative paths have prefix of @ or @/")
"figwheel-main.edn is valid \\(ツ)/"))
(process-main-config main-edn)))

(defn config-use-ssl [{:keys [::config] :as cfg}]
(if (:use-ssl config)
(let [ssl-port (get-in config [:ring-server-options :ssl-port] figwheel.repl/default-ssl-port)]
(-> cfg
(assoc-in [::config :ring-server-options :ssl-port] ssl-port)
(update-in [::config :ring-server-options :ssl?] (fnil identity true))
(update-in [::config :connect-url]
(fnil identity (format "wss://[[config-hostname]]:%d/figwheel-connect" ssl-port)))
(update-in [::config :open-url]
(fnil identity (format "https://[[server-hostname]]:%d" ssl-port)))))
cfg))

;; use tools reader read-string for better error messages
#_(redn/read-string)
(defn fetch-figwheel-main-edn [cfg]
Expand Down Expand Up @@ -1300,7 +1312,7 @@ I.E. {:closure-defines {cljs.core/*global* \"window\" ...}}"))
(:auto-testing (meta build-edn))
(update :extra-main-files assoc :auto-testing true)) }
(merge {::build {:id build-id}})
auto-bundle
config-auto-bundle
config-default-dirs
config-default-final-output-to
config-clean-outputs!)))
Expand Down Expand Up @@ -1716,7 +1728,8 @@ I.E. {:closure-defines {cljs.core/*global* \"window\" ...}}"))
config-update-watch-dirs
config-ensure-watch-dirs-on-classpath
config-figwheel-mode?
auto-bundle
config-auto-bundle
config-use-ssl
config-default-dirs
config-default-final-output-to
validate-output-paths-relationship!
Expand Down
25 changes: 25 additions & 0 deletions src/figwheel/main/schema/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,30 @@ Default value is nil
:clean-outputs true"
:group :common)

(s/def ::use-ssl boolean?)

(def-spec-meta ::use-ssl
:doc "Takes a boolean value that if true indicates that
figwheel.main should configure its server to use https.
This mainly adds default `:ring-server-options` for
:ssl? true
:ssl-port 9533
This also changes the default `:connect-url` to
`wss://[[config-hostname]]:<ssl-port>/figwheel-connect` and the
default `:open-url` to `https://[[server-hostname]]:<ssl-port>` where
`<ssl-port>` is replaced with the `:ssl-port` from
`:ring-server-options`.
To complete your SSL configuration you will need to provide a
certificate and keys to options to `:ring-server-options` via a Java
KeyStore.
:keystore <path to java keystore>
:password <password to the java keystore>"
:group :common)

;; ------ Uncommon options ----------------------------------

Expand Down Expand Up @@ -939,6 +963,7 @@ be useful for certain docker environments.
::final-output-to
::auto-bundle
::clean-outputs
::use-ssl

::cljsjs-resources

Expand Down

0 comments on commit 962524b

Please sign in to comment.