001  (ns ^{:doc "Set up and tear down the request handler."
002        :author "Simon Brooke"}
003    mw-ui.handler
004    (:require [compojure.core :refer [defroutes]]
005              [mw-ui.routes.home :refer [home-routes]]
006              [mw-ui.middleware :refer [load-middleware]]
007              [noir.response :refer [redirect]]
008              [noir.util.middleware :refer [app-handler]]
009              [compojure.route :as route]
010              [taoensso.timbre :as timbre]
011              ;; [taoensso.timbre.appenders.rotor :as rotor]
012              [selmer.parser :as parser]
013              [environ.core :refer [env]]))
014  
015  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
016  ;;;;
017  ;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
018  ;;;;
019  ;;;; This program is free software; you can redistribute it and/or
020  ;;;; modify it under the terms of the GNU General Public License
021  ;;;; as published by the Free Software Foundation; either version 2
022  ;;;; of the License, or (at your option) any later version.
023  ;;;;
024  ;;;; This program is distributed in the hope that it will be useful,
025  ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
026  ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
027  ;;;; GNU General Public License for more details.
028  ;;;;
029  ;;;; You should have received a copy of the GNU General Public License
030  ;;;; along with this program; if not, write to the Free Software
031  ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
032  ;;;; USA.
033  ;;;;
034  ;;;; Copyright (C) 2014 Simon Brooke
035  ;;;;
036  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
037  
038  (defroutes app-routes
039    (route/resources "/")
040    (route/not-found "Not Found"))
041  
042  
043  (defn init
044    "init will be called once when
045     app is deployed as a servlet on
046     an app server such as Tomcat
047     put any initialization code here"
048    []
049    ;; TODO fix timbre config!
050    ;; (timbre/set-config!
051    ;;   [:appenders :rotor]
052    ;;   {:min-level :info
053    ;;    :enabled? true
054    ;;    :async? false ; should be always false for rotor
055    ;;    :max-message-per-msecs nil
056    ;;    :fn rotor/appender-fn})
057    ;; (timbre/set-config!
058    ;;   [:shared-appender-config :rotor]
059    ;;   {:path "mw_ui.log" :max-size (* 512 1024) :backlog 10})
060  
061  
062    (when (env :dev) (parser/cache-off!))
063    (timbre/info "mw-ui started successfully"))
064  
065  
066  (defn destroy
067    "destroy will be called when your application
068     shuts down, put any clean up code here"
069    []
070    (timbre/info "mw-ui is shutting down..."))
071  
072  
073  (def app (app-handler
074             ;; add your application routes here
075             [home-routes app-routes]
076             ;; add custom middleware here
077             :middleware (load-middleware)
078             ;; timeout sessions after 30 minutes
079             :session-options {:timeout (* 60 30)
080                               :timeout-response (redirect "/")}
081             ;; add access rules here
082             :access-rules []
083             ;; serialize/deserialize the following data formats
084             ;; available formats:
085             ;; :json :json-kw :yaml :yaml-kw :edn :yaml-in-html
086             :formats [:json-kw :edn]))