mirror of
https://gitlab.com/wheres-the-tp/server.git
synced 2026-01-25 02:44:57 -06:00
move app config to separate module with main
This commit is contained in:
parent
842e78daef
commit
16bcc4de5d
4 changed files with 49 additions and 39 deletions
2
Procfile
2
Procfile
|
|
@ -1 +1 @@
|
|||
web: lein ring server-headless
|
||||
web: java $JVM_OPTS -cp target/aretherecookies.jar aretherecookies.app
|
||||
27
project.clj
27
project.clj
|
|
@ -2,21 +2,20 @@
|
|||
: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"]
|
||||
[environ "1.1.0"]
|
||||
[compojure "1.5.1"]
|
||||
[ring/ring-defaults "0.2.1"]
|
||||
[org.clojure/java.jdbc "0.7.3"]
|
||||
[org.postgresql/postgresql "42.1.4"]
|
||||
[com.mchange/c3p0 "0.9.5.2"]
|
||||
[ring-middleware-format "0.7.2"]
|
||||
[org.clojure/data.json "0.2.6"]
|
||||
[ring/ring-json "0.4.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"]
|
||||
[org.clojure/java.jdbc "0.7.3"]
|
||||
[org.postgresql/postgresql "42.1.4"]
|
||||
[com.mchange/c3p0 "0.9.5.2"]
|
||||
[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"]]}
|
||||
|
|
|
|||
15
src/aretherecookies/app.clj
Normal file
15
src/aretherecookies/app.clj
Normal 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})))
|
||||
|
|
@ -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]
|
||||
|
|
@ -11,14 +10,14 @@
|
|||
(defn uuid-to-string [key value]
|
||||
(if (instance? java.util.UUID value) (.toString value) value))
|
||||
|
||||
(defn get-coords [item]
|
||||
(->
|
||||
item
|
||||
(get :location)
|
||||
json/read-str
|
||||
(get "coordinates")))
|
||||
(defn get-coords [item]
|
||||
(->
|
||||
item
|
||||
(get :location)
|
||||
json/read-str
|
||||
(get "coordinates")))
|
||||
|
||||
(defn build-lat-lng [[lng lat]]
|
||||
(defn build-lat-lng [[lng lat]]
|
||||
(hash-map :longitude lng :latitude lat))
|
||||
|
||||
(defn build-latlng [item]
|
||||
|
|
@ -26,32 +25,29 @@
|
|||
(hash-map :longitude lng :latitude lat)))
|
||||
|
||||
(defn parse-location [item]
|
||||
(->
|
||||
item
|
||||
build-latlng
|
||||
(merge item)
|
||||
(dissoc :location)))
|
||||
(->
|
||||
item
|
||||
build-latlng
|
||||
(merge item)
|
||||
(dissoc :location)))
|
||||
|
||||
(defn food-items-to-json [query-result]
|
||||
(map parse-location query-result))
|
||||
(map parse-location query-result))
|
||||
|
||||
(defn food-items-handler [req]
|
||||
(println "req---->" (:body req))
|
||||
(let [{{lat "lat" lng "lng" filter "filter" orderby "orderby"} :body} req]
|
||||
(json/write-str
|
||||
(hash-map
|
||||
:orderby orderby
|
||||
:filter filter
|
||||
:fooditems (food-items-to-json
|
||||
(query-food-items (build-fooditems-query lng lat (get filter "radius")))))
|
||||
:value-fn uuid-to-string)))
|
||||
(hash-map
|
||||
:orderby orderby
|
||||
:filter filter
|
||||
:fooditems (food-items-to-json
|
||||
(query-food-items (build-fooditems-query lng lat (get filter "radius")))))
|
||||
:value-fn uuid-to-string)))
|
||||
|
||||
(defroutes app-routes
|
||||
(GET "/" [] (str {:csrf-token
|
||||
*anti-forgery-token*}))
|
||||
*anti-forgery-token*}))
|
||||
(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)))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue