update deps, reorg project files/config, and more
- remove lein-ring. focus on uberjar builds only (no war support now) while also allowing easy swapping out of standard jetty for jetty-async (thus, removal of lein-ring which does not support this) - "downgrade" to clojure/tools.logging. mainly out of preference for having logging work with dependencies using older logging solutions "out of the box" and using plain old log4j configuration
This commit is contained in:
parent
43ec433f31
commit
cad18b417f
|
@ -1,7 +1,8 @@
|
||||||
(ns leiningen.new.yawt
|
(ns leiningen.new.yawt
|
||||||
(:require [leiningen.new.templates :refer [renderer name-to-path sanitize sanitize-ns ->files]]
|
(:require
|
||||||
[leiningen.core.main :as main]
|
[leiningen.new.templates :refer [renderer name-to-path sanitize sanitize-ns ->files]]
|
||||||
[clojure.string :as str]))
|
[leiningen.core.main :as main]
|
||||||
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(def render (renderer "yawt"))
|
(def render (renderer "yawt"))
|
||||||
|
|
||||||
|
@ -15,15 +16,15 @@
|
||||||
#{"webapp"})
|
#{"webapp"})
|
||||||
|
|
||||||
(defn get-base-files [data]
|
(defn get-base-files [data]
|
||||||
[[".gitignore" (render "gitignore" data)]
|
[[".gitignore" (render "gitignore" data)]
|
||||||
["project.clj" (render "project.clj" data)]
|
["project.clj" (render "project.clj" data)]
|
||||||
["config/dev/config.edn" (render "config/dev/config.edn" data)]
|
["env-resources/dev/config.edn" (render "env-resources/dev/config.edn" data)]
|
||||||
["config/release/config.edn" (render "config/release/config.edn" data)]
|
["env-resources/uberjar/config.edn" (render "env-resources/uberjar/config.edn" data)]
|
||||||
["config/repl/config.edn" (render "config/repl/config.edn" data)]
|
["env-resources/repl/config.edn" (render "env-resources/repl/config.edn" data)]
|
||||||
["resources/log4j.properties" (render "resources/log4j.properties" data)]
|
["resources/log4j.properties" (render "resources/log4j.properties" data)]
|
||||||
["src/{{path}}/core.clj" (render "src/root_ns/core.clj" data)]
|
["src/{{path}}/core.clj" (render "src/root_ns/core.clj" data)]
|
||||||
["src/{{path}}/utils.clj" (render "src/root_ns/utils.clj" data)]
|
["src/{{path}}/utils.clj" (render "src/root_ns/utils.clj" data)]
|
||||||
["src/{{path}}/api/hello.clj" (render "src/root_ns/api/hello.clj" data)]])
|
["src/{{path}}/api/hello.clj" (render "src/root_ns/api/hello.clj" data)]])
|
||||||
|
|
||||||
(defn get-webapp-files [data]
|
(defn get-webapp-files [data]
|
||||||
["resources/public/cljs"
|
["resources/public/cljs"
|
||||||
|
@ -48,11 +49,11 @@
|
||||||
["resources/views/index.html" (render "resources/views/index.html" data)]
|
["resources/views/index.html" (render "resources/views/index.html" data)]
|
||||||
["resources/views/error.html" (render "resources/views/error.html" data)]
|
["resources/views/error.html" (render "resources/views/error.html" data)]
|
||||||
["resources/views/notfound.html" (render "resources/views/notfound.html" data)]
|
["resources/views/notfound.html" (render "resources/views/notfound.html" data)]
|
||||||
["src-cljs/{{path}}/client/main.cljs" (render "src-cljs/root_ns/client/main.cljs" data)]
|
["src/{{path}}/client/main.cljs" (render "src/root_ns/client/main.cljs" data)]
|
||||||
["src-cljs/{{path}}/client/page_components.cljs" (render "src-cljs/root_ns/client/page_components.cljs" data)]
|
["src/{{path}}/client/page_components.cljs" (render "src/root_ns/client/page_components.cljs" data)]
|
||||||
["src-cljs/{{path}}/client/utils.cljs" (render "src-cljs/root_ns/client/utils.cljs" data)]
|
["src/{{path}}/client/utils.cljs" (render "src/root_ns/client/utils.cljs" data)]
|
||||||
["src-cljs/{{path}}/client/routes/home.cljs" (render "src-cljs/root_ns/client/routes/home.cljs" data)]
|
["src/{{path}}/client/routes/home.cljs" (render "src/root_ns/client/routes/home.cljs" data)]
|
||||||
["src-cljs/{{path}}/client/routes/misc.cljs" (render "src-cljs/root_ns/client/routes/misc.cljs" data)]
|
["src/{{path}}/client/routes/misc.cljs" (render "src/root_ns/client/routes/misc.cljs" data)]
|
||||||
["src/{{path}}/middleware.clj" (render "src/root_ns/middleware_webapp.clj" data)]
|
["src/{{path}}/middleware.clj" (render "src/root_ns/middleware_webapp.clj" data)]
|
||||||
["src/{{path}}/routes.clj" (render "src/root_ns/routes_webapp.clj" data)]
|
["src/{{path}}/routes.clj" (render "src/root_ns/routes_webapp.clj" data)]
|
||||||
["src/{{path}}/views.clj" (render "src/root_ns/views_webapp.clj" data)]
|
["src/{{path}}/views.clj" (render "src/root_ns/views_webapp.clj" data)]
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
(ns user
|
(ns user
|
||||||
(:require weasel.repl.websocket
|
(:require
|
||||||
cemerick.piggieback
|
weasel.repl.websocket
|
||||||
[edn-config.core :refer [env]])
|
cemerick.piggieback
|
||||||
(:use {{root-ns}}.core))
|
[edn-config.core :refer [env]])
|
||||||
|
(:use
|
||||||
|
{{root-ns}}.core))
|
||||||
|
|
||||||
(defn cljs-repl
|
(defn cljs-repl
|
||||||
"after establishing a normal repl with leiningen (e.g. by running 'lein repl') *and* after
|
"after establishing a normal repl with leiningen (e.g. by running 'lein repl') *and* after
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
(ns user
|
(ns user
|
||||||
(:require [edn-config.core :refer [env]])
|
(:require
|
||||||
(:use {{root-ns}}.core))
|
[edn-config.core :refer [env]])
|
||||||
|
(:use
|
||||||
|
{{root-ns}}.core))
|
||||||
|
|
||||||
(if (env :auto-start-server?)
|
(if (env :auto-start-server?)
|
||||||
(.start (Thread. #(start-server))))
|
(.start (Thread. #(start-server))))
|
||||||
|
|
|
@ -3,43 +3,44 @@
|
||||||
:url "http://example.com/FIXME"
|
:url "http://example.com/FIXME"
|
||||||
:min-lein-version "2.0.0"
|
:min-lein-version "2.0.0"
|
||||||
|
|
||||||
:source-paths ["src"{{#webapp}} "src-cljs"{{/webapp}}]
|
|
||||||
:main {{root-ns}}.core
|
:main {{root-ns}}.core
|
||||||
|
|
||||||
:dependencies [[org.clojure/clojure "1.6.0"]
|
:dependencies [[org.clojure/clojure "1.6.0"]
|
||||||
[compojure "1.2.1"]
|
[compojure "1.3.1"]
|
||||||
[metosin/ring-http-response "0.4.0"]
|
[metosin/ring-http-response "0.5.2"]
|
||||||
[lib-noir "0.9.4"]
|
[lib-noir "0.9.5" :exclusions [javax.servlet/servlet-api]]
|
||||||
|
[ring-custom-jetty-server "0.1.0"]
|
||||||
[ring-server "0.3.1"]
|
[ring-server "0.3.1"]
|
||||||
{{#webapp}}
|
{{#webapp}}
|
||||||
[org.clojure/clojurescript "0.0-2371"]
|
[org.clojure/clojurescript "0.0-2511"]
|
||||||
[weasel "0.4.2"]
|
[weasel "0.4.2"]
|
||||||
[clj-pebble "0.2.0"]
|
[clj-pebble "0.2.0"]
|
||||||
[secretary "1.2.1"]
|
[secretary "1.2.1"]
|
||||||
[reagent "0.4.3"]
|
[reagent "0.5.0-alpha"]
|
||||||
[cljs-ajax "0.3.3"]
|
[cljs-ajax "0.3.3"]
|
||||||
{{/webapp}}
|
{{/webapp}}
|
||||||
{{#webservice}}
|
{{#webservice}}
|
||||||
[hiccup "1.0.5"]
|
[hiccup "1.0.5"]
|
||||||
{{/webservice}}
|
{{/webservice}}
|
||||||
{{#postgresql}}
|
{{#postgresql}}
|
||||||
[org.clojure/java.jdbc "0.3.5"]
|
[org.clojure/java.jdbc "0.3.6"]
|
||||||
[postgresql/postgresql "8.4-702.jdbc4"]
|
[org.postgresql/postgresql "9.2-1003-jdbc4"]
|
||||||
[ragtime "0.3.7"]
|
[clojurewerkz/ragtime "0.4.0"]
|
||||||
{{/postgresql}}
|
{{/postgresql}}
|
||||||
{{#couchdb}}
|
{{#couchdb}}
|
||||||
[com.ashafa/clutch "0.4.0"]
|
[com.ashafa/clutch "0.4.0"]
|
||||||
[com.cemerick/url "0.1.1"]
|
[com.cemerick/url "0.1.1"]
|
||||||
{{/couchdb}}
|
{{/couchdb}}
|
||||||
[com.taoensso/timbre "3.3.1"]
|
[org.clojure/tools.logging "0.3.1"]
|
||||||
|
[log4j "1.2.16"]
|
||||||
|
[org.slf4j/slf4j-log4j12 "1.7.1"]
|
||||||
[edn-config "0.2"]
|
[edn-config "0.2"]
|
||||||
[prone "0.6.0"]]
|
[prone "0.8.0"]]
|
||||||
|
|
||||||
:plugins [[lein-ring "0.8.13"]
|
:plugins [[lein-environ "1.0.0"]
|
||||||
{{#webapp}}
|
{{#webapp}}
|
||||||
[lein-cljsbuild "1.0.3"]
|
[lein-cljsbuild "1.0.3"]
|
||||||
{{/webapp}}
|
{{/webapp}}
|
||||||
[lein-environ "1.0.0"]
|
|
||||||
[lein-pprint "1.1.1"]]
|
[lein-pprint "1.1.1"]]
|
||||||
|
|
||||||
{{#webapp}}
|
{{#webapp}}
|
||||||
|
@ -50,42 +51,42 @@
|
||||||
:repl-options {:init-ns user}
|
:repl-options {:init-ns user}
|
||||||
{{/webservice}}
|
{{/webservice}}
|
||||||
|
|
||||||
:ring {:handler {{root-ns}}.core/app
|
|
||||||
:init {{root-ns}}.core/init
|
|
||||||
:destroy {{root-ns}}.core/destroy
|
|
||||||
:port 8080}
|
|
||||||
|
|
||||||
{{#webapp}}
|
{{#webapp}}
|
||||||
:cljsbuild {:builds [{:id "dev"
|
:cljsbuild {:builds {:main
|
||||||
:source-paths ["src-cljs"]
|
{:source-paths ["src/{{path}}/client"]
|
||||||
:compiler {:output-to "resources/public/cljs/main.js"
|
:compiler {:output-to "resources/public/cljs/main.js"
|
||||||
:source-map "resources/public/cljs/main.js.map"
|
:source-map "resources/public/cljs/main.js.map"
|
||||||
:output-dir "resources/public/cljs/target"
|
:output-dir "resources/public/cljs/target"
|
||||||
:optimizations :none
|
:externs ["externs/jquery.js"]
|
||||||
:pretty-print true}}
|
:optimizations :none
|
||||||
{:id "release"
|
:pretty-print true}}}}
|
||||||
:source-paths ["src-cljs"]
|
|
||||||
:compiler {:output-to "resources/public/cljs/main.js"
|
|
||||||
:optimizations :advanced
|
|
||||||
:pretty-print false
|
|
||||||
:output-wrapper false
|
|
||||||
:externs ["externs/jquery.js"]
|
|
||||||
:closure-warnings {:non-standard-jsdoc :off}}}]}
|
|
||||||
|
|
||||||
{{/webapp}}
|
{{/webapp}}
|
||||||
:profiles {:release {:resource-paths ["config/release"]
|
:profiles {:uberjar {:resource-paths ["env-resources/uberjar"]
|
||||||
:aot :all
|
:aot :all
|
||||||
|
:omit-source true
|
||||||
|
{{#webapp}}
|
||||||
|
:hooks [leiningen.cljsbuild]
|
||||||
|
:cljsbuild {:jar true
|
||||||
|
:builds {:main
|
||||||
|
{:compiler ^:replace
|
||||||
|
{:output-to "resources/public/cljs/main.js"
|
||||||
|
:optimizations :advanced
|
||||||
|
:pretty-print false}}}}
|
||||||
|
{{/webapp}}
|
||||||
:ring {:open-browser? false
|
:ring {:open-browser? false
|
||||||
:stacktraces? false
|
:stacktraces? false
|
||||||
:auto-reload? false}}
|
:auto-reload? false}}
|
||||||
:dev {:resource-paths ["config/dev"]
|
:dev {:resource-paths ["env-resources/dev"]
|
||||||
:dependencies [[ring-mock "0.1.5"]
|
:dependencies [{{#webapp}}[com.cemerick/piggieback "0.1.3"]{{/webapp}}
|
||||||
[ring/ring-devel "1.3.1"]
|
|
||||||
{{#webapp}}
|
|
||||||
[com.cemerick/piggieback "0.1.3"]
|
|
||||||
{{/webapp}}
|
|
||||||
[pjstadig/humane-test-output "0.6.0"]]
|
[pjstadig/humane-test-output "0.6.0"]]
|
||||||
|
{{#postgresql}}
|
||||||
|
:ragtime {:migrations ragtime.sql.files/migrations
|
||||||
|
:database "jdbc:postgresql://localhost:5432/db_name?user=username&password=password"}
|
||||||
|
{{/postgresql}}
|
||||||
:injections [(require 'pjstadig.humane-test-output)
|
:injections [(require 'pjstadig.humane-test-output)
|
||||||
(pjstadig.humane-test-output/activate!)]}
|
(pjstadig.humane-test-output/activate!)]}
|
||||||
:repl {:resource-paths ["config/repl"]
|
:repl {:resource-paths ["env-resources/repl"]
|
||||||
:source-paths ["dev"]}})
|
:source-paths ["dev"]}}
|
||||||
|
:aliases {"uberjar" ["do" "clean" {{#webapp}}["cljsbuild" "clean"]{{/webapp}} "uberjar"]{{#webapp}}
|
||||||
|
"mkcljs" ["do" ["cljsbuild" "clean"] ["cljsbuild" "once"] ["cljsbuild" "auto"]]{{/webapp}}})
|
|
@ -1,16 +1,13 @@
|
||||||
### direct log messages to stdout ###
|
log4j.rootLogger=INFO, stdout, R
|
||||||
|
|
||||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||||
log4j.appender.stdout.Target=System.out
|
log4j.appender.stdout.Target=System.out
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
log4j.appender.stdout.layout.ConversionPattern=%d %-5p %c - %m%n
|
||||||
log4j.rootLogger=info, stdout
|
|
||||||
|
|
||||||
### file appender log ###
|
log4j.appender.R=org.apache.log4j.RollingFileAppender
|
||||||
log4j.logger.clojure.core=INFO, rollingFile
|
log4j.appender.R.File=${log4j.logdir}{{root-ns}}.log
|
||||||
|
log4j.appender.R.MaxFileSize=10MB
|
||||||
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
|
log4j.appender.R.MaxBackupIndex=20
|
||||||
log4j.appender.rollingFile.File=${log4j.logdir}{{root-ns}}.log
|
log4j.appender.R.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.rollingFile.MaxFileSize=1MB
|
log4j.appender.R.layout.ConversionPattern=%d %-5p %c - %m%n
|
||||||
log4j.appender.rollingFile.MaxBackupIndex=1000
|
|
||||||
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.rollingFile.layout.ConversionPattern=%m%n
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
@ -1,11 +1,12 @@
|
||||||
(ns {{root-ns}}.client.main
|
(ns {{root-ns}}.client.main
|
||||||
(:require [weasel.repl :as ws-repl]
|
(:require
|
||||||
[reagent.core :as reagent]
|
[weasel.repl :as ws-repl]
|
||||||
[secretary.core :as secretary :refer-macros [defroute]]
|
[reagent.core :as reagent]
|
||||||
[{{root-ns}}.client.page-components :refer [app-page]]
|
[secretary.core :as secretary :refer-macros [defroute]]
|
||||||
[{{root-ns}}.client.utils :refer [hook-browser-navigation! dev? supports-ws?]]
|
[{{root-ns}}.client.page-components :refer [app-page]]
|
||||||
[{{root-ns}}.client.routes.home :refer [home-page]]
|
[{{root-ns}}.client.utils :refer [hook-browser-navigation! dev? supports-ws?]]
|
||||||
[{{root-ns}}.client.routes.misc :refer [notfound-page]]))
|
[{{root-ns}}.client.routes.home :refer [home-page]]
|
||||||
|
[{{root-ns}}.client.routes.misc :refer [notfound-page]]))
|
||||||
|
|
||||||
(defn page [page-component & args]
|
(defn page [page-component & args]
|
||||||
(reagent/render-component
|
(reagent/render-component
|
||||||
|
@ -20,7 +21,7 @@
|
||||||
|
|
||||||
(defroute "*" [] (page notfound-page))
|
(defroute "*" [] (page notfound-page))
|
||||||
|
|
||||||
(defn init-app []
|
(defn init-app! []
|
||||||
(when (dev?)
|
(when (dev?)
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
(if (and (supports-ws?)
|
(if (and (supports-ws?)
|
||||||
|
@ -29,4 +30,4 @@
|
||||||
(secretary/set-config! :prefix "#")
|
(secretary/set-config! :prefix "#")
|
||||||
(hook-browser-navigation!))
|
(hook-browser-navigation!))
|
||||||
|
|
||||||
(init-app)
|
(init-app!)
|
|
@ -1,6 +1,7 @@
|
||||||
(ns {{root-ns}}.client.routes.home
|
(ns {{root-ns}}.client.routes.home
|
||||||
(:require [reagent.core :refer [atom]]
|
(:require
|
||||||
[{{root-ns}}.client.utils :refer [api-fetch!]]))
|
[reagent.core :refer [atom]]
|
||||||
|
[{{root-ns}}.client.utils :refer [api-fetch!]]))
|
||||||
|
|
||||||
(defn home-page []
|
(defn home-page []
|
||||||
(let [hello-response (atom nil)]
|
(let [hello-response (atom nil)]
|
|
@ -1,11 +1,13 @@
|
||||||
(ns {{root-ns}}.client.utils
|
(ns {{root-ns}}.client.utils
|
||||||
(:import goog.History)
|
(:import
|
||||||
(:require [clojure.string :as str]
|
goog.History)
|
||||||
[clojure.walk :refer [keywordize-keys]]
|
(:require
|
||||||
[ajax.core :refer [GET]]
|
[clojure.string :as str]
|
||||||
[goog.events :as events]
|
[clojure.walk :refer [keywordize-keys]]
|
||||||
[goog.history.EventType :as EventType]
|
[ajax.core :refer [GET]]
|
||||||
[secretary.core :as secretary]))
|
[goog.events :as events]
|
||||||
|
[goog.history.EventType :as EventType]
|
||||||
|
[secretary.core :as secretary]))
|
||||||
|
|
||||||
(defn dev?
|
(defn dev?
|
||||||
"returns true if running in a dev build"
|
"returns true if running in a dev build"
|
|
@ -1,73 +1,73 @@
|
||||||
(ns {{root-ns}}.core
|
(ns {{root-ns}}.core
|
||||||
(:gen-class)
|
(:gen-class)
|
||||||
(:require [compojure.core :refer [defroutes]]
|
(:require
|
||||||
[compojure.route :as route]
|
[compojure.core :refer [defroutes]]
|
||||||
[noir.util.middleware :refer [app-handler]]
|
[compojure.route :as route]
|
||||||
[taoensso.timbre :refer [log set-config!]]
|
[noir.util.middleware :refer [app-handler]]
|
||||||
[ring.middleware.file-info :refer [wrap-file-info]]
|
[clojure.tools.logging :refer [info]]
|
||||||
[ring.server.standalone :refer [serve]]
|
[ring-custom-jetty.server.standalone :refer [serve]]
|
||||||
[ring.middleware.file :refer [wrap-file]]
|
[ring.adapter.jetty :refer [run-jetty]]
|
||||||
{{#webapp}}
|
{{#webapp}}
|
||||||
[clj-pebble.core :as pebble]
|
[clj-pebble.core :as pebble]
|
||||||
[clj-pebble.web.middleware :refer [wrap-servlet-context-path]]
|
[clj-pebble.web.middleware :refer [wrap-servlet-context-path]]
|
||||||
{{/webapp}}
|
{{/webapp}}
|
||||||
[edn-config.core :refer [env]]
|
[edn-config.core :refer [env]]
|
||||||
[prone.middleware :as prone]
|
[prone.middleware :as prone]
|
||||||
{{#postgresql}}
|
{{#postgresql}}
|
||||||
[{{root-ns}}.db :as db]
|
[{{root-ns}}.db :as db]
|
||||||
{{/postgresql}}
|
{{/postgresql}}
|
||||||
[{{root-ns}}.routes :refer [main-public-routes api-routes]]
|
[{{root-ns}}.routes :refer [main-public-routes api-routes]]
|
||||||
[{{root-ns}}.middleware :refer [wrap-exceptions not-found-handler]]
|
[{{root-ns}}.middleware :refer [wrap-exceptions not-found-handler]]))
|
||||||
[{{root-ns}}.utils :refer [log-formatter]]))
|
|
||||||
|
|
||||||
(defroutes default-handler-routes
|
|
||||||
(route/resources "/")
|
|
||||||
(not-found-handler))
|
|
||||||
|
|
||||||
(def app
|
|
||||||
(app-handler
|
|
||||||
[main-public-routes api-routes default-handler-routes]
|
|
||||||
:middleware [(if (env :dev)
|
|
||||||
prone/wrap-exceptions
|
|
||||||
wrap-exceptions){{#webapp}}
|
|
||||||
wrap-servlet-context-path{{/webapp}}]
|
|
||||||
:access-rules []
|
|
||||||
:formats [:json-kw :edn]))
|
|
||||||
|
|
||||||
(defn init []
|
(defn init []
|
||||||
(set-config! [:shared-appender-config :spit-filename] "{{root-ns}}.log")
|
(info "Starting up ...")
|
||||||
(set-config! [:appenders :spit :enabled?] true)
|
|
||||||
(set-config! [:fmt-output-fn] log-formatter)
|
|
||||||
|
|
||||||
(log :info "Starting up ...")
|
|
||||||
|
|
||||||
(if (env :repl)
|
(if (env :repl)
|
||||||
(log :info "Running in REPL."))
|
(info "Running in REPL."))
|
||||||
|
|
||||||
{{#webapp}}
|
{{#webapp}}
|
||||||
(when (env :dev)
|
(when (env :dev)
|
||||||
(log :info "Running in :dev environment.")
|
(info "Running in :dev environment.")
|
||||||
(pebble/set-options! :cache false
|
(pebble/set-options!
|
||||||
:check-for-minified-web-resources false))
|
:cache false
|
||||||
|
:check-for-minified-web-resources false))
|
||||||
{{/webapp}}
|
{{/webapp}}
|
||||||
{{#webservice}}
|
{{#webservice}}
|
||||||
(when (env :dev)
|
(when (env :dev)
|
||||||
(log :info "Running in :dev environment."))
|
(info "Running in :dev environment."))
|
||||||
{{/webservice}}
|
{{/webservice}}
|
||||||
{{#postgresql}}
|
{{#postgresql}}
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(db/init!)
|
(db/init!)
|
||||||
(log :info "Database access initialized.")
|
(info "Database access initialized.")
|
||||||
(catch Exception ex
|
(catch Exception ex
|
||||||
(throw (Exception. "Database not available or bad connection information specified." ex))))
|
(throw (Exception. "Database not available or bad connection information specified." ex))))
|
||||||
{{/postgresql}}
|
{{/postgresql}}
|
||||||
|
|
||||||
(log :info "Application init finished."))
|
(info "Application init finished."))
|
||||||
|
|
||||||
(defn destroy []
|
(defn destroy []
|
||||||
(log :info "Shutting down ..."))
|
(info "Shutting down ..."))
|
||||||
|
|
||||||
|
(defn wrap-env-middleware [handler]
|
||||||
|
(if (env :dev)
|
||||||
|
(-> handler (prone/wrap-exceptions))
|
||||||
|
(-> handler (wrap-exceptions))))
|
||||||
|
|
||||||
|
(defroutes default-handler-routes
|
||||||
|
(route/resources "/")
|
||||||
|
(not-found-handler))
|
||||||
|
|
||||||
|
(defn get-handler []
|
||||||
|
(app-handler
|
||||||
|
[main-public-routes
|
||||||
|
api-routes
|
||||||
|
default-handler-routes]
|
||||||
|
:middleware [wrap-env-middleware{{#webapp}}
|
||||||
|
wrap-servlet-context-path{{/webapp}}]
|
||||||
|
:access-rules []
|
||||||
|
:formats [:json-kw :edn]))
|
||||||
|
|
||||||
;; support functions for starting the web app in a REPL / running an uberjar directly
|
;; support functions for starting the web app in a REPL / running an uberjar directly
|
||||||
;; (not used otherwise)
|
;; (not used otherwise)
|
||||||
|
@ -76,18 +76,18 @@
|
||||||
|
|
||||||
(defn start-server [& [port]]
|
(defn start-server [& [port]]
|
||||||
(let [port (if port (Integer/parseInt port) 8080)]
|
(let [port (if port (Integer/parseInt port) 8080)]
|
||||||
(reset! server
|
(reset!
|
||||||
(serve
|
server
|
||||||
(-> #'app
|
(serve
|
||||||
(wrap-file "resources")
|
(get-handler)
|
||||||
(wrap-file-info))
|
{:run-server-fn run-jetty
|
||||||
{:port port
|
:port port
|
||||||
:init init
|
:init init
|
||||||
:auto-reload? true
|
:auto-reload? (env :dev)
|
||||||
:destroy destroy
|
:destroy destroy
|
||||||
:join? false
|
:join? false
|
||||||
:open-browser? (not (env :dont-open-browser?))}))
|
:open-browser? (not (env :dont-open-browser?))}))
|
||||||
(println (str "You can view the site at http://localhost:" port))))
|
(info (str "Serving app at http://localhost:" port "/"))))
|
||||||
|
|
||||||
(defn stop-server []
|
(defn stop-server []
|
||||||
(.stop @server)
|
(.stop @server)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
(ns {{root-ns}}.db
|
(ns {{root-ns}}.db
|
||||||
(:require [com.ashafa.clutch :as couch]
|
(:require
|
||||||
[com.ashafa.clutch.utils :as couch-utils]
|
[com.ashafa.clutch :as couch]
|
||||||
[cemerick.url :as url]
|
[com.ashafa.clutch.utils :as couch-utils]
|
||||||
[taoensso.timbre :refer [log]]
|
[cemerick.url :as url]
|
||||||
[edn-config.core :refer [env]]))
|
[edn-config.core :refer [env]]))
|
||||||
|
|
||||||
(defn db-url [db-name]
|
(defn db-url [db-name]
|
||||||
(let [db-config (env :db)
|
(let [db-config (env :db)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
(ns {{root-ns}}.db
|
(ns {{root-ns}}.db
|
||||||
(:import (org.postgresql.ds PGPoolingDataSource))
|
(:import
|
||||||
(:require [clojure.java.jdbc :as sql]
|
(org.postgresql.ds PGPoolingDataSource))
|
||||||
[edn-config.core :refer [env]]))
|
(:require
|
||||||
|
[clojure.java.jdbc :as sql]
|
||||||
|
[edn-config.core :refer [env]]))
|
||||||
|
|
||||||
(defonce db (atom nil))
|
(defonce db (atom nil))
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
(ns {{root-ns}}.middleware
|
(ns {{root-ns}}.middleware
|
||||||
(:require [taoensso.timbre :refer [log]]
|
(:require
|
||||||
[noir.response :as response]
|
[clojure.tools.logging :refer [error]]
|
||||||
[{{root-ns}}.views :as views])
|
[noir.response :as response]
|
||||||
(:use {{root-ns}}.utils))
|
[{{root-ns}}.views :as views])
|
||||||
|
(:use
|
||||||
|
{{root-ns}}.utils))
|
||||||
|
|
||||||
(defn- api-request? [request]
|
(defn- api-request? [request]
|
||||||
(.startsWith
|
(.startsWith
|
||||||
|
@ -16,7 +18,7 @@
|
||||||
(try
|
(try
|
||||||
(handler request)
|
(handler request)
|
||||||
(catch Throwable ex
|
(catch Throwable ex
|
||||||
(log :error ex "Unhandled exception.")
|
(error ex "Unhandled exception.")
|
||||||
(if (api-request? request)
|
(if (api-request? request)
|
||||||
(->> (response/json
|
(->> (response/json
|
||||||
{:status "error"
|
{:status "error"
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
(ns {{root-ns}}.middleware
|
(ns {{root-ns}}.middleware
|
||||||
(:require [taoensso.timbre :refer [log]]
|
(:require
|
||||||
[noir.response :as response]
|
[clojure.tools.logging :refer [error]]
|
||||||
[{{root-ns}}.views :as views])
|
[noir.response :as response]
|
||||||
(:use {{root-ns}}.utils))
|
[{{root-ns}}.views :as views])
|
||||||
|
(:use
|
||||||
|
{{root-ns}}.utils))
|
||||||
|
|
||||||
(defn- api-request? [request]
|
(defn- api-request? [request]
|
||||||
(.startsWith
|
(.startsWith
|
||||||
|
@ -16,7 +18,7 @@
|
||||||
(try
|
(try
|
||||||
(handler request)
|
(handler request)
|
||||||
(catch Throwable ex
|
(catch Throwable ex
|
||||||
(log :error ex "Unhandled exception.")
|
(error ex "Unhandled exception.")
|
||||||
(if (api-request? request)
|
(if (api-request? request)
|
||||||
(->> (response/json
|
(->> (response/json
|
||||||
{:status "error"
|
{:status "error"
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
(ns {{root-ns}}.routes
|
(ns {{root-ns}}.routes
|
||||||
(:require [compojure.core :refer [defroutes context GET]]
|
(:require
|
||||||
[{{root-ns}}.api.hello :as hello-api]
|
[compojure.core :refer [defroutes context GET]]
|
||||||
[{{root-ns}}.views :as views]))
|
[{{root-ns}}.api.hello :as hello-api]
|
||||||
|
[{{root-ns}}.views :as views]))
|
||||||
|
|
||||||
(defroutes
|
(defroutes
|
||||||
main-public-routes
|
main-public-routes
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
(ns {{root-ns}}.routes
|
(ns {{root-ns}}.routes
|
||||||
(:require [compojure.core :refer [defroutes context GET]]
|
(:require
|
||||||
[{{root-ns}}.api.hello :as hello-api]
|
[compojure.core :refer [defroutes context GET]]
|
||||||
[{{root-ns}}.views :as views]))
|
[{{root-ns}}.api.hello :as hello-api]
|
||||||
|
[{{root-ns}}.views :as views]))
|
||||||
|
|
||||||
(defroutes
|
(defroutes
|
||||||
main-public-routes
|
main-public-routes
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
(ns {{root-ns}}.utils
|
(ns {{root-ns}}.utils
|
||||||
(:require [clojure.string :as str]
|
(:require
|
||||||
[clojure.stacktrace :refer [print-stack-trace]]))
|
[clojure.stacktrace :refer [print-stack-trace]]))
|
||||||
|
|
||||||
(defn get-throwable-stack-trace [throwable]
|
(defn get-throwable-stack-trace [throwable]
|
||||||
(if throwable
|
(if throwable
|
||||||
(with-out-str
|
(with-out-str
|
||||||
(print-stack-trace throwable))))
|
(print-stack-trace throwable))))
|
||||||
|
|
||||||
(defn log-formatter [{:keys [level throwable message timestamp hostname ns]} & [{:keys [nofonts?] :as appender-fmt-output-opts}]]
|
|
||||||
(format "%s %s %s [%s] - %s%s"
|
|
||||||
timestamp hostname (-> level name str/upper-case) ns (or message "")
|
|
||||||
(or (get-throwable-stack-trace throwable) "")))
|
|
|
@ -1,10 +1,11 @@
|
||||||
(ns {{root-ns}}.views
|
(ns {{root-ns}}.views
|
||||||
(:require [clojure.string :as str]
|
(:require
|
||||||
[clj-pebble.core :as pebble]
|
[clojure.string :as str]
|
||||||
[clj-pebble.web.middleware :refer [*servlet-context-path*]]
|
[clj-pebble.core :as pebble]
|
||||||
[ring.util.response :as response]
|
[clj-pebble.web.middleware :refer [*servlet-context-path*]]
|
||||||
[compojure.response :refer [Renderable]]
|
[ring.util.response :as response]
|
||||||
[edn-config.core :refer [env]]))
|
[compojure.response :refer [Renderable]]
|
||||||
|
[edn-config.core :refer [env]]))
|
||||||
|
|
||||||
(def template-path "views/")
|
(def template-path "views/")
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
(ns {{root-ns}}.views
|
(ns {{root-ns}}.views
|
||||||
(:require [ring.util.response :as response]
|
(:require
|
||||||
[compojure.response :refer [Renderable]])
|
[ring.util.response :as response]
|
||||||
(:use hiccup.core
|
[compojure.response :refer [Renderable]])
|
||||||
hiccup.page))
|
(:use
|
||||||
|
hiccup.core
|
||||||
|
hiccup.page))
|
||||||
|
|
||||||
(defn render-response [request page-fn & {:keys [params status content-type]}]
|
(defn render-response [request page-fn & {:keys [params status content-type]}]
|
||||||
(-> (page-fn request params)
|
(-> (page-fn request params)
|
||||||
|
|
Reference in a new issue