001  (ns ^{:doc "In truth, boilerplate from Luminus."
002        :author "Simon Brooke"}
003   mw-ui.middleware
004    (:require [taoensso.timbre :as timbre]
005              [environ.core :refer [env]]
006              [selmer.middleware :refer [wrap-error-page]]
007              [noir-exception.core
008               :refer [wrap-internal-error wrap-exceptions]]))
009  
010  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
011  ;;;;
012  ;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
013  ;;;;
014  ;;;; This program is free software; you can redistribute it and/or
015  ;;;; modify it under the terms of the GNU General Public License
016  ;;;; as published by the Free Software Foundation; either version 2
017  ;;;; of the License, or (at your option) any later version.
018  ;;;;
019  ;;;; This program is distributed in the hope that it will be useful,
020  ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
021  ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
022  ;;;; GNU General Public License for more details.
023  ;;;;
024  ;;;; You should have received a copy of the GNU General Public License
025  ;;;; along with this program; if not, write to the Free Software
026  ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
027  ;;;; USA.
028  ;;;;
029  ;;;; Copyright (C) 2014 Simon Brooke
030  ;;;;
031  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
032  
033  
034  (defn log-request [handler]
035    (fn [req]
036      (timbre/debug req)
037      (handler req)))
038  
039  
040  (def development-middleware
041    [log-request
042     wrap-error-page
043     wrap-exceptions])
044  
045  
046  (def production-middleware
047    [#(wrap-internal-error % :log (fn [e] (timbre/error e)))])
048  
049  
050  (defn load-middleware []
051    (concat (when (env :dev) development-middleware)
052            production-middleware))