summaryrefslogtreecommitdiff
path: root/src/config.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.clj')
-rwxr-xr-xsrc/config.clj70
1 files changed, 53 insertions, 17 deletions
diff --git a/src/config.clj b/src/config.clj
index 1481855..f8f3d7e 100755
--- a/src/config.clj
+++ b/src/config.clj
@@ -1,33 +1,69 @@
(ns config
- (:import java.lang.System))
+ (:import java.lang.System
+ java.net.URL))
;; Configuration
(def *server-user* (System/getProperty "user.name"))
+(defn getenv
+ ([k] (System/getenv k))
+ ([k default]
+ (let [v (System/getenv k)]
+ (if (and v (not= v "")) v default))))
+
+(defn getenv-int
+ ([k default]
+ (let [v (getenv k nil)]
+ (if v (Integer/parseInt v) default))))
+
+(defn getenv-bool
+ ([k default]
+ (let [v (getenv k nil)]
+ (if (nil? v)
+ default
+ (contains? #{"1" "true" "yes" "on"} (.toLowerCase v))))))
+
(def *server-url*
- (if (= *server-user* "dumpfmprod")
- ;"http://dump.fm"
- "http://asdf.us:8080"))
+ (getenv "DUMPFM_SERVER_URL"
+ (if (= *server-user* "dumpfmprod")
+ "/"
+ "http://localhost:8080")))
+
+(def *public-host*
+ (getenv "DUMPFM_PUBLIC_HOST"
+ (try
+ (.getHost (URL. *server-url*))
+ (catch Exception _ ""))))
+
+(def *public-scheme*
+ (getenv "DUMPFM_PUBLIC_SCHEME"
+ (try
+ (.getProtocol (URL. *server-url*))
+ (catch Exception _ "http"))))
(def *cookie-domain*
- (if (= *server-user* "dumpfmprod")
- ;".dump.fm" ; is this ok or should I comment this too? this too
- ; not clojure specialist, but all this stuff doesn't look good, app should be able to run from any location and still work as usual, domains shouldn't
- ; be hardcoded at all. in html paths can be relative, which removes need to figure out which domain you running app on. I hear you,
- ; let's just get it working though, right? sure
- ""))
+ (getenv "DUMPFM_COOKIE_DOMAIN"
+ (if (= *server-user* "dumpfmprod")
+ ".dump.fm"
+ "")))
+
+(def *passwordless-login*
+ (getenv-bool "DUMPFM_PASSWORDLESS_LOGIN" false))
(def db-server
- (if (= *server-user* "dumpfmprod")
- "localhost"; "192.168.162.138"
- "localhost"))
+ (getenv "DUMPFM_DB_HOST"
+ (if (= *server-user* "dumpfmprod")
+ "localhost"; "192.168.162.138"
+ "localhost")))
(def redis-server
- (if (= *server-user* "dumpfmprod")
- ;{:host "192.168.156.111" :port 6379 :db 0 } ;these ip addresses need to change right? yes should I try deleting this? or statically
- ;setting it to my public ip? why public ip, it should be just 127.0.0.1 or something like redis.dump.fm if you plan to have more than one server.
- {:host "127.0.0.1" :port 6379 :db 0 }))
+ {:host (getenv "DUMPFM_REDIS_HOST"
+ (if (= *server-user* "dumpfmprod")
+ "127.0.0.1"
+ "127.0.0.1"))
+ :port (getenv-int "DUMPFM_REDIS_PORT" 6379)
+ :db (getenv-int "DUMPFM_REDIS_DB" 0)})
(def *root-directory* (System/getProperty "user.dir"))
(def *image-directory* "images")