about summary refs log tree commit diff
path: root/src/pronouns/web.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/pronouns/web.clj')
-rw-r--r--src/pronouns/web.clj46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/pronouns/web.clj b/src/pronouns/web.clj
index 23ac603..eda8376 100644
--- a/src/pronouns/web.clj
+++ b/src/pronouns/web.clj
@@ -1,3 +1,19 @@
+;; pronoun.is - a website for pronoun usage examples
+;; Copyright (C) 2014 - 2016 Morgan Astra
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU Affero General Public License as
+;; published by the Free Software Foundation, either version 3 of the
+;; License, or (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU Affero General Public License for more details.
+
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>
+
 (ns pronouns.web
   (:require [compojure.core :refer [defroutes GET PUT POST DELETE ANY]]
             [compojure.handler :refer [site]]
@@ -6,24 +22,19 @@
             [clojure.string :as s]
             [ring.middleware.logger :as logger]
             [ring.middleware.stacktrace :as trace]
-            [ring.middleware.session :as session]
-            [ring.middleware.session.cookie :as cookie]
+            [ring.middleware.params :as params]
             [ring.adapter.jetty :as jetty]
             [environ.core :refer [env]]
             [pronouns.util :as u]
             [pronouns.pages :as pages]))
 
-(def config {:default-server-port 5000
-             :pronoun-table-path "resources/pronouns.tab"})
-(def pronouns-table (u/slurp-tabfile (:pronoun-table-path config)))
-
 (defroutes app-routes
   (GET "/" []
        {:status 200
         :headers {"Content-Type" "text/html"}
-        :body (pages/front pronouns-table)})
+        :body (pages/front)})
 
-  (GET "/pronouns.css" {params :params}
+  (GET "/pronouns.css" []
      {:status 200
      :headers {"Content-Type" "text/css"}
      :body (slurp (io/resource "pronouns.css"))})
@@ -31,7 +42,7 @@
   (GET "/*" {params :params}
        {:status 200
         :headers {"Content-Type" "text/html"}
-        :body (pages/pronouns (:* params) pronouns-table)})
+        :body (pages/pronouns params)})
 
   (ANY "*" []
        (route/not-found (slurp (io/resource "404.html")))))
@@ -40,21 +51,18 @@
   (fn [req]
     (try (handler req)
          (catch Exception e
-           {:status 500
-            :headers {"Content-Type" "text/html"}
-            :body (slurp (io/resource "500.html"))}))))
+           (binding [*out* *err*]
+             {:status 500
+              :headers {"Content-Type" "text/html"}
+              :body (slurp (io/resource "500.html"))})))))
 
 (def app
   (-> app-routes
       logger/wrap-with-logger
       wrap-error-page
-      trace/wrap-stacktrace))
+      trace/wrap-stacktrace
+      params/wrap-params))
 
 (defn -main []
-  (let [port (Integer. (:port env
-                              (:default-server-port config)))]
+  (let [port (Integer. (:port env))]
     (jetty/run-jetty app {:port port})))
-
-;; For interactive development:
-;; (.stop server)
-;; (def server (-main))