move app config to separate module with main

This commit is contained in:
Bart Akeley 2017-10-30 20:34:16 -05:00
parent 842e78daef
commit 16bcc4de5d
4 changed files with 49 additions and 39 deletions

View file

@ -1 +1 @@
web: lein ring server-headless
web: java $JVM_OPTS -cp target/aretherecookies.jar aretherecookies.app

View file

@ -2,9 +2,8 @@
:description "where cookies can be found"
:url "http://www.aretherecookies.com"
:min-lein-version "2.0.0"
:main aretherecookies.handler
:dependencies [
[org.clojure/clojure "1.8.0"]
:main aretherecookies.app
:dependencies [[org.clojure/clojure "1.8.0"]
[environ "1.1.0"]
[compojure "1.5.1"]
[ring/ring-defaults "0.2.1"]
@ -14,9 +13,9 @@
[ring-middleware-format "0.7.2"]
[org.clojure/data.json "0.2.6"]
[ring/ring-json "0.4.0"]
]
[ring/ring-jetty-adapter "1.4.0"]]
:plugins [[lein-ring "0.9.7"] [lein-environ "1.1.0"]]
:ring {:handler aretherecookies.handler/app}
:ring {:handler aretherecookies.app/app}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.0"]]}

View file

@ -0,0 +1,15 @@
(ns aretherecookies.app
(:gen-class)
(:require [aretherecookies.handler :refer [app-routes]]
[environ.core :refer [env]]
[compojure.handler :refer [site]]
[ring.adapter.jetty :as jetty]
[ring.middleware.defaults :refer [wrap-defaults api-defaults]]))
(def app-config (assoc-in api-defaults [:security :anti-forgery] false))
(def app (wrap-defaults app-routes app-config))
(defn -main [& [port]]
(let [port (Integer. (or port (env :port) 3000))]
(jetty/run-jetty (site #'app) {:port port :join? false})))

View file

@ -2,7 +2,6 @@
(:require [aretherecookies.db :refer [query-food-items build-fooditems-query]]
[compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
[clojure.data.json :as json]
[clojure.string :as str]
[ring.middleware.anti-forgery :refer :all]
@ -52,6 +51,3 @@
(POST "/test" req "ok")
(POST "/fooditems" req (wrap-json-body food-items-handler))
(GET "/echo" [location orderby filter] (str location orderby filter)))
(def app
(wrap-defaults app-routes (assoc-in site-defaults [:security :anti-forgery] false)))