Add ip binding and handle errors
This commit is contained in:
parent
23e76b5e69
commit
b4377c371a
5 changed files with 35 additions and 35 deletions
3
env/dev/resources/config.edn
vendored
3
env/dev/resources/config.edn
vendored
|
@ -1,5 +1,6 @@
|
||||||
{:dev true
|
{:dev true
|
||||||
:port 3000
|
:port 3000
|
||||||
|
:host "0.0.0.0"
|
||||||
:creator-password "creator"
|
:creator-password "creator"
|
||||||
:user-password "user"
|
:user-password "user"
|
||||||
;; when :nrepl-port is set the application starts the nREPL server on load
|
;; when :nrepl-port is set the application starts the nREPL server on load
|
||||||
|
@ -10,5 +11,5 @@
|
||||||
:basepath "http://localhost"
|
:basepath "http://localhost"
|
||||||
:authors ["Aaron Fischer"]
|
:authors ["Aaron Fischer"]
|
||||||
|
|
||||||
:images_per_page 25
|
:images-per-page 25
|
||||||
}
|
}
|
||||||
|
|
3
env/prod/resources/config.edn
vendored
3
env/prod/resources/config.edn
vendored
|
@ -2,11 +2,12 @@
|
||||||
:creator-password "xxx"
|
:creator-password "xxx"
|
||||||
:user-password "yyy"
|
:user-password "yyy"
|
||||||
:port 3000
|
:port 3000
|
||||||
|
:host "0.0.0.0"
|
||||||
|
|
||||||
:database-url "jdbc:sqlite:yenu.db"
|
:database-url "jdbc:sqlite:yenu.db"
|
||||||
|
|
||||||
:basepath "http://localhost"
|
:basepath "http://localhost"
|
||||||
:authors ["Aaron Fischer"]
|
:authors ["Aaron Fischer"]
|
||||||
|
|
||||||
:images_per_page 25
|
:images-per-page 25
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,34 +4,29 @@
|
||||||
[luminus.http-server :as http]
|
[luminus.http-server :as http]
|
||||||
[luminus-migrations.core :as migrations]
|
[luminus-migrations.core :as migrations]
|
||||||
[yenu.config :refer [env]]
|
[yenu.config :refer [env]]
|
||||||
[clojure.tools.cli :refer [parse-opts]]
|
|
||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
[yenu.helpers.images :as image]
|
[yenu.helpers.images :as image]
|
||||||
[mount.core :as mount])
|
[mount.core :as mount])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
(def cli-options
|
(mount/defstate ^{:on-reload :noop}
|
||||||
[["-p" "--port PORT" "Port number"
|
http-server
|
||||||
:parse-fn #(Integer/parseInt %)]])
|
:start
|
||||||
|
(http/start
|
||||||
|
(-> env
|
||||||
|
(assoc :handler (handler/app))
|
||||||
|
(update :port #(or (-> env :options :port) %))))
|
||||||
|
:stop
|
||||||
|
(http/stop http-server))
|
||||||
|
|
||||||
(mount/defstate ^{:on-reload :noop}
|
(mount/defstate ^{:on-reload :noop}
|
||||||
http-server
|
repl-server
|
||||||
:start
|
:start
|
||||||
(http/start
|
(when-let [nrepl-port (env :nrepl-port)]
|
||||||
(-> env
|
(repl/start {:port nrepl-port}))
|
||||||
(assoc :handler (handler/app))
|
:stop
|
||||||
(update :port #(or (-> env :options :port) %))))
|
(when repl-server
|
||||||
:stop
|
(repl/stop repl-server)))
|
||||||
(http/stop http-server))
|
|
||||||
|
|
||||||
(mount/defstate ^{:on-reload :noop}
|
|
||||||
repl-server
|
|
||||||
:start
|
|
||||||
(when-let [nrepl-port (env :nrepl-port)]
|
|
||||||
(repl/start {:port nrepl-port}))
|
|
||||||
:stop
|
|
||||||
(when repl-server
|
|
||||||
(repl/stop repl-server)))
|
|
||||||
|
|
||||||
|
|
||||||
(defn stop-app []
|
(defn stop-app []
|
||||||
|
@ -41,7 +36,6 @@
|
||||||
|
|
||||||
(defn start-app [args]
|
(defn start-app [args]
|
||||||
(doseq [component (-> args
|
(doseq [component (-> args
|
||||||
(parse-opts cli-options)
|
|
||||||
mount/start-with-args
|
mount/start-with-args
|
||||||
:started)]
|
:started)]
|
||||||
(log/info component "started"))
|
(log/info component "started"))
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
(page (inc current) (= current num) "disabled" (h/html "Weiter " [:span.fa.fa-arrow-right]))])))
|
(page (inc current) (= current num) "disabled" (h/html "Weiter " [:span.fa.fa-arrow-right]))])))
|
||||||
|
|
||||||
(defn index-page [current request]
|
(defn index-page [current request]
|
||||||
(let [image-count (:images_per_page env)
|
(let [image-count (:images-per-page env)
|
||||||
offset (* (dec current) image-count)
|
offset (* (dec current) image-count)
|
||||||
pages (number-of-pages image-count)
|
pages (number-of-pages image-count)
|
||||||
images (db/get-all-images {:offset offset :count image-count})]
|
images (db/get-all-images {:offset offset :count image-count})]
|
||||||
|
@ -69,14 +69,17 @@
|
||||||
next-img (db/get-next-image {:image-date (:created_at image)})
|
next-img (db/get-next-image {:image-date (:created_at image)})
|
||||||
prev-img (db/get-prev-image {:image-date (:created_at image)})
|
prev-img (db/get-prev-image {:image-date (:created_at image)})
|
||||||
saved-author (get-in request [:cookies "author" :value])]
|
saved-author (get-in request [:cookies "author" :value])]
|
||||||
(layout/render-file "detail.html"
|
(if (not (nil? image))
|
||||||
{:image image
|
(layout/render-file "detail.html"
|
||||||
:flash (:flash request)
|
{:image image
|
||||||
:next-image next-img
|
:flash (:flash request)
|
||||||
:prev-image prev-img
|
:next-image next-img
|
||||||
:tags (db/get-tags-for-image {:id (:id image)})
|
:prev-image prev-img
|
||||||
:saved-author saved-author
|
:tags (db/get-tags-for-image {:id (:id image)})
|
||||||
:comments (db/get-comments-for-image {:image_id (:id image)})})))
|
:saved-author saved-author
|
||||||
|
:comments (db/get-comments-for-image {:image_id (:id image)})})
|
||||||
|
(layout/error-page {:status 404
|
||||||
|
:title "page not found"}))))
|
||||||
|
|
||||||
(defn add-comment! [image-id request]
|
(defn add-comment! [image-id request]
|
||||||
(let [author (:author (:params request))
|
(let [author (:author (:params request))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
basepath=http://localhost
|
basepath=http://127.0.0.1
|
||||||
|
host=0.0.0.0
|
||||||
port=3000
|
port=3000
|
||||||
|
|
||||||
# Passwords
|
# Passwords
|
||||||
|
@ -6,5 +7,5 @@ user-password=user
|
||||||
creator-password=creator
|
creator-password=creator
|
||||||
|
|
||||||
# Content stuff
|
# Content stuff
|
||||||
images_per_page=25
|
images-per-page=25
|
||||||
authors=Aaron Fischer,Beatrice Fischer
|
authors=Aaron Fischer,Beatrice Fischer
|
||||||
|
|
Loading…
Reference in a new issue