-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port from environment override does not work #12
Comments
This is how I cope with it: (defmethod ig/prep-key :server/jetty
[_ config]
; in PROD, get the port number from env variables instead of from the config.edn
(let [port (env :port)]
(if port
(merge config {:port (Integer/parseInt port)})
config))) The smarter way would be as you suggested: (defmethod ig/prep-key :server/jetty
[_ config]
; in PROD, get the port number from env variables instead of from the config.edn
(let [port (env :port)]
(merge config
(and port {:port (Integer/parseInt port)})))) Personally I prefer the former. |
I still don't think that either of the code snippets I proposed last comment are idiomatic Clojure yet. After looking around for a while, I think this is the most idiomatic one (with (defmethod ig/prep-key :adapter/jetty
[_ config]
; in PROD, get the port number from env variables instead of from the config.edn
(merge config (some->> env
(:port)
(Integer/parseInt)
(assoc {} :port)))) |
I stumbled on this one right now. Of course we could safeguard this in different ways ... I'm trying to understand why? I think it's appropriate at the system start to get this message. What am I missing? If you really want you could set a default value: (defmethod ig/prep-key :server/jetty
[_ {:keys [port] :or {port 3000}]
(merge config {:port port})) But I feel like this will beat the purpose of this failing. I think you want to get notified with Please if you could elaborate more on this I would like to understand BTW. The whole config for prod is reworked toward end of the course |
In increment 11
ig/prep-key :server/jetty
is added, however it cannot execute withoutPORT
being explicitly set: https://github.com/jacekschae/learn-reitit-course-files/blob/master/increments/11-integrant-reloaded/src/cheffy/server.clj#L14If
PORT
is unset the server will fail to launch with:Execution error (NumberFormatException) at java.lang.Integer/parseInt (Integer.java:630). Cannot parse null string
. Additionallymerge
will always overwrite the key:port
set inresources/config.edn
.This may be solved by catching the
NumberFormatException
and potentially usingor
should the value benil
The text was updated successfully, but these errors were encountered: