update so everything at least runs (mostly!) with the new dependencies
This commit is contained in:
parent
8062b2e433
commit
70f0f92a58
|
@ -8,11 +8,11 @@
|
||||||
blarg.config
|
blarg.config
|
||||||
ring.middleware.head
|
ring.middleware.head
|
||||||
compojure.core)
|
compojure.core)
|
||||||
(:require [noir.util.middleware :as middleware]
|
(:require [noir.util.middleware :refer [app-handler]]
|
||||||
[noir.response :as resp]
|
[noir.response :as resp]
|
||||||
[compojure.route :as route]
|
[compojure.route :as route]
|
||||||
[taoensso.timbre :as timbre]
|
[taoensso.timbre :as timbre]
|
||||||
[com.postspectacular.rotor :as rotor]
|
[taoensso.timbre.appenders.rotor :as rotor]
|
||||||
[selmer.parser :as parser]
|
[selmer.parser :as parser]
|
||||||
[blarg.views.layout :as layout]
|
[blarg.views.layout :as layout]
|
||||||
[blarg.models.db :as db]))
|
[blarg.models.db :as db]))
|
||||||
|
@ -25,54 +25,43 @@
|
||||||
:headers {"Content-Type" "text/html"}
|
:headers {"Content-Type" "text/html"}
|
||||||
:body (layout/render "notfound.html")})))
|
:body (layout/render "notfound.html")})))
|
||||||
|
|
||||||
(defn init
|
(defn init []
|
||||||
"init will be called once when
|
|
||||||
app is deployed as a servlet on
|
|
||||||
an app server such as Tomcat
|
|
||||||
put any initialization code here"
|
|
||||||
[]
|
|
||||||
(timbre/set-config!
|
(timbre/set-config!
|
||||||
[:appenders :rotor]
|
[:appenders :rotor]
|
||||||
{:min-level :info
|
{:min-level :info
|
||||||
:enabled? true
|
:enabled? true
|
||||||
:async? false ; should be always false for rotor
|
:async? false ; should be always false for rotor
|
||||||
:max-message-per-msecs nil
|
:max-message-per-msecs nil
|
||||||
:fn rotor/append})
|
:fn rotor/appender-fn})
|
||||||
|
|
||||||
(timbre/set-config!
|
(timbre/set-config!
|
||||||
[:shared-appender-config :rotor]
|
[:shared-appender-config :rotor]
|
||||||
{:path "blarg.log" :max-size 10000 :backlog 10})
|
{:path "blarg.log" :max-size (* 512 1024) :backlog 10})
|
||||||
|
|
||||||
(timbre/info "blarg started successfully")
|
(timbre/info "blarg started successfully")
|
||||||
|
|
||||||
(if (= "DEV" (config-val :env))
|
(when (= "DEV" (config-val :env))
|
||||||
|
(timbre/info "Dev environment. Template caching disabled.")
|
||||||
(parser/toggle-caching))
|
(parser/toggle-caching))
|
||||||
|
|
||||||
(timbre/info "touching database...")
|
(timbre/info "touching database...")
|
||||||
(db/touch-databases))
|
(db/touch-databases))
|
||||||
|
|
||||||
(defn destroy
|
(defn destroy []
|
||||||
"destroy will be called when your application
|
|
||||||
shuts down, put any clean up code here"
|
|
||||||
[]
|
|
||||||
(timbre/info "blarg is shutting down..."))
|
(timbre/info "blarg is shutting down..."))
|
||||||
|
|
||||||
(defn wrap-exceptions [app]
|
(defn wrap-exceptions [handler]
|
||||||
(fn [request]
|
(fn [request]
|
||||||
(try
|
(try
|
||||||
(app request)
|
(handler request)
|
||||||
(catch Exception e
|
(catch Throwable e
|
||||||
(.printStackTrace e)
|
(.printStackTrace e)
|
||||||
{:status 500
|
{:status 500
|
||||||
:headers {"Content-Type" "text/html"}
|
:headers {"Content-Type" "text/html"}
|
||||||
:body (layout/render "error.html" {:error-info e})}))))
|
:body (layout/render "error.html" {:error-info e})}))))
|
||||||
|
|
||||||
;;append your application routes to the all-routes vector
|
(def app (app-handler
|
||||||
(def all-routes [auth-routes home-routes posts-routes files-routes rss-routes])
|
[auth-routes home-routes posts-routes files-routes rss-routes app-routes]
|
||||||
|
|
||||||
(def app (middleware/app-handler
|
|
||||||
(conj all-routes app-routes)
|
|
||||||
:middleware [wrap-exceptions]
|
:middleware [wrap-exceptions]
|
||||||
:access-rules [[{:redirect "/unauthorized"} auth-required]]))
|
:access-rules [[{:redirect "/unauthorized"} auth-required]]
|
||||||
|
:formats [:json-kw :edn]))
|
||||||
(def war-handler (middleware/war-handler app))
|
|
||||||
|
|
|
@ -6,33 +6,21 @@
|
||||||
(defonce server (atom nil))
|
(defonce server (atom nil))
|
||||||
|
|
||||||
(defn get-handler []
|
(defn get-handler []
|
||||||
;; #'app expands to (var app) so that when we reload our code,
|
|
||||||
;; the server is forced to re-resolve the symbol in the var
|
|
||||||
;; rather than having its own copy. When the root binding
|
|
||||||
;; changes, the server picks it up without having to restart.
|
|
||||||
(-> #'app
|
(-> #'app
|
||||||
; Makes static assets in $PROJECT_DIR/resources/public/ available.
|
(wrap-file "resources")
|
||||||
(wrap-file "resources")
|
(wrap-file-info)))
|
||||||
; Content-Type, Content-Length, and Last Modified headers for files in body
|
|
||||||
(wrap-file-info)))
|
|
||||||
|
|
||||||
(defn start-server
|
(defn start-server [& [port]]
|
||||||
"used for starting the server in development mode from REPL"
|
(let [port (if port (Integer/parseInt port) 3000)]
|
||||||
[& [port]]
|
|
||||||
(let [port (if port (Integer/parseInt port) 8080)]
|
|
||||||
(reset! server
|
(reset! server
|
||||||
(serve (get-handler)
|
(serve (get-handler)
|
||||||
{:port port
|
{:port port
|
||||||
:init init
|
:init init
|
||||||
:auto-reload? true
|
:auto-reload? true
|
||||||
:destroy destroy
|
:destroy destroy
|
||||||
:join true}))
|
:join? false}))
|
||||||
(println (str "You can view the site at http://localhost:" port))))
|
(println (str "You can view the site at http://localhost:" port))))
|
||||||
|
|
||||||
(defn stop-server []
|
(defn stop-server []
|
||||||
(.stop @server)
|
(.stop @server)
|
||||||
(reset! server nil))
|
(reset! server nil))
|
||||||
|
|
||||||
#_(start-server)
|
|
||||||
|
|
||||||
#_(stop-server)
|
|
||||||
|
|
|
@ -40,4 +40,4 @@
|
||||||
(GET "/login" [] (login-page))
|
(GET "/login" [] (login-page))
|
||||||
(POST "/login" [id pass] (handle-login id pass))
|
(POST "/login" [id pass] (handle-login id pass))
|
||||||
(GET "/logout" [] (logout))
|
(GET "/logout" [] (logout))
|
||||||
(restricted GET "/private" [] "private!"))
|
(GET "/private" [] (restricted "private!")))
|
||||||
|
|
|
@ -70,11 +70,11 @@
|
||||||
(resp/redirect "/notfound")))
|
(resp/redirect "/notfound")))
|
||||||
|
|
||||||
(defroutes files-routes
|
(defroutes files-routes
|
||||||
(restricted GET "/listfiles" [] (list-files "/"))
|
(GET "/listfiles" [] (restricted (list-files "/")))
|
||||||
(restricted GET "/listfiles/*" [*] (list-files *))
|
(GET "/listfiles/*" [*] (restricted (list-files *)))
|
||||||
(restricted POST "/uploadfile" [path file returnpath] (handle-new-file (ensure-prefix-suffix path "/") file returnpath))
|
(POST "/uploadfile" [path file returnpath] (restricted (handle-new-file (ensure-prefix-suffix path "/") file returnpath)))
|
||||||
(restricted POST "/updatefile" [id file returnpath] (handle-update-file (ensure-prefix id "/") file returnpath))
|
(POST "/updatefile" [id file returnpath] (restricted (handle-update-file (ensure-prefix id "/") file returnpath)))
|
||||||
(restricted POST "/deletefile" [id returnpath] (handle-delete-file (ensure-prefix id "/") returnpath))
|
(POST "/deletefile" [id returnpath] (restricted (handle-delete-file (ensure-prefix id "/") returnpath)))
|
||||||
(restricted GET "/publishfile/*" [* returnpath] (handle-publish-file * true returnpath))
|
(GET "/publishfile/*" [* returnpath] (restricted (handle-publish-file * true returnpath)))
|
||||||
(restricted GET "/unpublishfile/*" [* returnpath] (handle-publish-file * false returnpath))
|
(GET "/unpublishfile/*" [* returnpath] (restricted (handle-publish-file * false returnpath)))
|
||||||
(GET "/files/*" [*] (get-file *)))
|
(GET "/files/*" [*] (get-file *)))
|
||||||
|
|
|
@ -131,10 +131,10 @@
|
||||||
(show-post-page year month day slug))
|
(show-post-page year month day slug))
|
||||||
(GET "/tag/:tag" [tag] (list-by-tag tag))
|
(GET "/tag/:tag" [tag] (list-by-tag tag))
|
||||||
(GET "/archive" [] (list-archive))
|
(GET "/archive" [] (list-archive))
|
||||||
(restricted GET "/newpost" [] (new-post-page))
|
(GET "/newpost" [] (restricted (new-post-page)))
|
||||||
(restricted POST "/newpost" [title tags body] (handle-new-post title tags body))
|
(POST "/newpost" [title tags body] (restricted (handle-new-post title tags body)))
|
||||||
(restricted GET "/editpost/:id" [id] (edit-post-page id))
|
(GET "/editpost/:id" [id] (restricted (edit-post-page id)))
|
||||||
(restricted POST "/editpost/:id" [id title tags body] (handle-edit-post id title tags body))
|
(POST "/editpost/:id" [id title tags body] (restricted (handle-edit-post id title tags body)))
|
||||||
(restricted GET "/publish/:id" [id reset-date] (handle-publish-post id true reset-date))
|
(GET "/publish/:id" [id reset-date] (restricted (handle-publish-post id true reset-date)))
|
||||||
(restricted GET "/unpublish/:id" [id] (handle-publish-post id false false))
|
(GET "/unpublish/:id" [id] (restricted (handle-publish-post id false false)))
|
||||||
(restricted GET "/deletepost/:id" [id] (handle-delete-post id)))
|
(GET "/deletepost/:id" [id] (restricted (handle-delete-post id))))
|
||||||
|
|
|
@ -28,4 +28,4 @@
|
||||||
(doall))))))
|
(doall))))))
|
||||||
|
|
||||||
(defroutes rss-routes
|
(defroutes rss-routes
|
||||||
(GET "/rss" [] (handle-rss)))
|
(GET "/rss" [] (handle-rss)))
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
(ns blarg.views.layout
|
(ns blarg.views.layout
|
||||||
(:use noir.request)
|
|
||||||
(:require [selmer.parser :as parser]
|
(:require [selmer.parser :as parser]
|
||||||
[noir.session :as session]
|
[ring.util.response :refer [content-type response]]
|
||||||
[blarg.views.viewfilters]))
|
[compojure.response :refer [Renderable]]
|
||||||
|
[noir.session :as session])
|
||||||
|
(:use [blarg.views.viewfilters]))
|
||||||
|
|
||||||
(def template-path "blarg/views/templates/")
|
(def template-path "blarg/views/templates/")
|
||||||
|
|
||||||
|
(deftype RenderableTemplate [template params]
|
||||||
|
Renderable
|
||||||
|
(render [this request]
|
||||||
|
(content-type
|
||||||
|
(response
|
||||||
|
(parser/render-file
|
||||||
|
(str template-path template)
|
||||||
|
(assoc params
|
||||||
|
:context (:context request)
|
||||||
|
:user-id (session/get :user))))
|
||||||
|
"text/html; charset=utf-8")))
|
||||||
|
|
||||||
(defn render [template & [params]]
|
(defn render [template & [params]]
|
||||||
(parser/render-file
|
(RenderableTemplate. template params))
|
||||||
(str template-path template)
|
|
||||||
(assoc params
|
|
||||||
:context (:context *request*)
|
|
||||||
:user-id (session/get :user))))
|
|
||||||
|
|
Reference in a new issue