Add ip binding and handle errors

This commit is contained in:
Aaron Fischer 2018-05-04 14:21:31 +02:00 committed by Aaron Fischer
parent 23e76b5e69
commit b4377c371a
No known key found for this signature in database
GPG key ID: A62EFAEA293B99D7
5 changed files with 35 additions and 35 deletions

View file

@ -1,5 +1,6 @@
{:dev true
:port 3000
:host "0.0.0.0"
:creator-password "creator"
:user-password "user"
;; when :nrepl-port is set the application starts the nREPL server on load
@ -10,5 +11,5 @@
:basepath "http://localhost"
:authors ["Aaron Fischer"]
:images_per_page 25
:images-per-page 25
}

View file

@ -2,11 +2,12 @@
:creator-password "xxx"
:user-password "yyy"
:port 3000
:host "0.0.0.0"
:database-url "jdbc:sqlite:yenu.db"
:basepath "http://localhost"
:authors ["Aaron Fischer"]
:images_per_page 25
:images-per-page 25
}

View file

@ -4,34 +4,29 @@
[luminus.http-server :as http]
[luminus-migrations.core :as migrations]
[yenu.config :refer [env]]
[clojure.tools.cli :refer [parse-opts]]
[clojure.tools.logging :as log]
[yenu.helpers.images :as image]
[mount.core :as mount])
(:gen-class))
(def cli-options
[["-p" "--port PORT" "Port number"
:parse-fn #(Integer/parseInt %)]])
(mount/defstate ^{:on-reload :noop}
http-server
:start
(http/start
(-> env
(assoc :handler (handler/app))
(update :port #(or (-> env :options :port) %))))
:stop
(http/stop http-server))
(mount/defstate ^{:on-reload :noop}
http-server
:start
(http/start
(-> env
(assoc :handler (handler/app))
(update :port #(or (-> env :options :port) %))))
:stop
(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)))
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 []
@ -41,7 +36,6 @@
(defn start-app [args]
(doseq [component (-> args
(parse-opts cli-options)
mount/start-with-args
:started)]
(log/info component "started"))

View file

@ -54,7 +54,7 @@
(page (inc current) (= current num) "disabled" (h/html "Weiter " [:span.fa.fa-arrow-right]))])))
(defn index-page [current request]
(let [image-count (:images_per_page env)
(let [image-count (:images-per-page env)
offset (* (dec current) image-count)
pages (number-of-pages 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)})
prev-img (db/get-prev-image {:image-date (:created_at image)})
saved-author (get-in request [:cookies "author" :value])]
(layout/render-file "detail.html"
{:image image
:flash (:flash request)
:next-image next-img
:prev-image prev-img
:tags (db/get-tags-for-image {:id (:id image)})
:saved-author saved-author
:comments (db/get-comments-for-image {:image_id (:id image)})})))
(if (not (nil? image))
(layout/render-file "detail.html"
{:image image
:flash (:flash request)
:next-image next-img
:prev-image prev-img
:tags (db/get-tags-for-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]
(let [author (:author (:params request))

View file

@ -1,4 +1,5 @@
basepath=http://localhost
basepath=http://127.0.0.1
host=0.0.0.0
port=3000
# Passwords
@ -6,5 +7,5 @@ user-password=user
creator-password=creator
# Content stuff
images_per_page=25
images-per-page=25
authors=Aaron Fischer,Beatrice Fischer