diff --git a/.gitignore b/.gitignore
index a4cb69a..829d866 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,5 @@ pom.xml.asc
.lein-failures
.nrepl-port
.cpcache/
+.log
+log
diff --git a/Capstanfile b/Capstanfile
new file mode 100644
index 0000000..86dd223
--- /dev/null
+++ b/Capstanfile
@@ -0,0 +1,28 @@
+
+#
+# Name of the base image. Capstan will download this automatically from
+# Cloudius S3 repository.
+#
+#base: cloudius/osv
+base: cloudius/osv-openjdk8
+
+#
+# The command line passed to OSv to start up the application.
+#
+cmdline: /java.so -jar /shapey-shifty/app.jar
+
+#
+# The command to use to build the application.
+# You can use any build tool/command (make/rake/lein/boot) - this runs locally on your machine
+#
+# For Leiningen, you can use:
+#build: lein uberjar
+# For Boot, you can use:
+#build: boot build
+
+#
+# List of files that are included in the generated image.
+#
+files:
+ /shapey-shifty/app.jar: ./target/uberjar/shapey-shifty.jar
+
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..6cac633
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,7 @@
+FROM openjdk:8-alpine
+
+COPY target/uberjar/shapey-shifty.jar /shapey-shifty/app.jar
+
+EXPOSE 3000
+
+CMD ["java", "-jar", "/shapey-shifty/app.jar"]
diff --git a/Procfile b/Procfile
new file mode 100644
index 0000000..2e9db52
--- /dev/null
+++ b/Procfile
@@ -0,0 +1 @@
+web: java -cp target/uberjar/shapey-shifty.jar clojure.main -m shapey-shifty.core
diff --git a/README.md b/README.md
index 565934f..bd60c00 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,21 @@
-# ShapeyShifty
-Personal CRM for the IndieWeb
+# shapey-shifty
+
+generated using Luminus version "3.55"
+
+FIXME
+
+## Prerequisites
+
+You will need [Leiningen][1] 2.0 or above installed.
+
+[1]: https://github.com/technomancy/leiningen
+
+## Running
+
+To start a web server for the application, run:
+
+ lein run
+
+## License
+
+Copyright © 2020 FIXME
diff --git a/dev-config.edn b/dev-config.edn
new file mode 100644
index 0000000..d27bc99
--- /dev/null
+++ b/dev-config.edn
@@ -0,0 +1,10 @@
+;; WARNING
+;; The dev-config.edn file is used for local environment variables, such as database credentials.
+;; This file is listed in .gitignore and will be excluded from version control by Git.
+
+{:dev true
+ :port 3000
+ ;; when :nrepl-port is set the application starts the nREPL server on load
+ :nrepl-port 7000
+
+ }
diff --git a/env/dev/clj/shapey_shifty/dev_middleware.clj b/env/dev/clj/shapey_shifty/dev_middleware.clj
new file mode 100644
index 0000000..66b5aad
--- /dev/null
+++ b/env/dev/clj/shapey_shifty/dev_middleware.clj
@@ -0,0 +1,11 @@
+(ns shapey-shifty.dev-middleware
+ (:require
+ [ring.middleware.reload :refer [wrap-reload]]
+ [selmer.middleware :refer [wrap-error-page]]
+ [prone.middleware :refer [wrap-exceptions]]))
+
+(defn wrap-dev [handler]
+ (-> handler
+ wrap-reload
+ wrap-error-page
+ (wrap-exceptions {:app-namespaces ['shapey-shifty]})))
diff --git a/env/dev/clj/shapey_shifty/env.clj b/env/dev/clj/shapey_shifty/env.clj
new file mode 100644
index 0000000..252857a
--- /dev/null
+++ b/env/dev/clj/shapey_shifty/env.clj
@@ -0,0 +1,15 @@
+(ns shapey-shifty.env
+ (:require
+ [selmer.parser :as parser]
+ [clojure.tools.logging :as log]
+ [shapey-shifty.dev-middleware :refer [wrap-dev]]))
+
+(def defaults
+ {:init
+ (fn []
+ (parser/cache-off!)
+ (log/info "\n-=[shapey-shifty started successfully using the development profile]=-"))
+ :stop
+ (fn []
+ (log/info "\n-=[shapey-shifty has shut down successfully]=-"))
+ :middleware wrap-dev})
diff --git a/env/dev/clj/user.clj b/env/dev/clj/user.clj
new file mode 100644
index 0000000..65cd7a8
--- /dev/null
+++ b/env/dev/clj/user.clj
@@ -0,0 +1,32 @@
+(ns user
+ "Userspace functions you can run by default in your local REPL."
+ (:require
+ [shapey-shifty.config :refer [env]]
+ [clojure.pprint]
+ [clojure.spec.alpha :as s]
+ [expound.alpha :as expound]
+ [mount.core :as mount]
+ [shapey-shifty.core :refer [start-app]]))
+
+(alter-var-root #'s/*explain-out* (constantly expound/printer))
+
+(add-tap (bound-fn* clojure.pprint/pprint))
+
+(defn start
+ "Starts application.
+ You'll usually want to run this on startup."
+ []
+ (mount/start-without #'shapey-shifty.core/repl-server))
+
+(defn stop
+ "Stops application."
+ []
+ (mount/stop-except #'shapey-shifty.core/repl-server))
+
+(defn restart
+ "Restarts application."
+ []
+ (stop)
+ (start))
+
+
diff --git a/env/dev/resources/config.edn b/env/dev/resources/config.edn
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/env/dev/resources/config.edn
@@ -0,0 +1 @@
+{}
diff --git a/env/dev/resources/logback.xml b/env/dev/resources/logback.xml
new file mode 100644
index 0000000..8219609
--- /dev/null
+++ b/env/dev/resources/logback.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+ UTF-8
+ %date{ISO8601} [%thread] %-5level %logger{36} - %msg %n
+
+
+
+ log/shapey-shifty.log
+
+ log/shapey-shifty.%d{yyyy-MM-dd}.%i.log
+
+ 100MB
+
+
+ 30
+
+
+ UTF-8
+ %date{ISO8601} [%thread] %-5level %logger{36} - %msg %n
+
+
+
+
+
+
+
+
+
+
diff --git a/env/prod/clj/shapey_shifty/env.clj b/env/prod/clj/shapey_shifty/env.clj
new file mode 100644
index 0000000..f4eb6a3
--- /dev/null
+++ b/env/prod/clj/shapey_shifty/env.clj
@@ -0,0 +1,11 @@
+(ns shapey-shifty.env
+ (:require [clojure.tools.logging :as log]))
+
+(def defaults
+ {:init
+ (fn []
+ (log/info "\n-=[shapey-shifty started successfully]=-"))
+ :stop
+ (fn []
+ (log/info "\n-=[shapey-shifty has shut down successfully]=-"))
+ :middleware identity})
diff --git a/env/prod/resources/config.edn b/env/prod/resources/config.edn
new file mode 100644
index 0000000..e24ec21
--- /dev/null
+++ b/env/prod/resources/config.edn
@@ -0,0 +1,2 @@
+{:prod true
+ :port 3000}
diff --git a/env/prod/resources/logback.xml b/env/prod/resources/logback.xml
new file mode 100644
index 0000000..9975a5b
--- /dev/null
+++ b/env/prod/resources/logback.xml
@@ -0,0 +1,25 @@
+
+
+
+
+ log/shapey-shifty.log
+
+ log/shapey-shifty.%d{yyyy-MM-dd}.%i.log
+
+ 100MB
+
+
+ 30
+
+
+ UTF-8
+ %date{ISO8601} [%thread] %-5level %logger{36} - %msg %n
+
+
+
+
+
+
+
+
+
diff --git a/env/test/resources/config.edn b/env/test/resources/config.edn
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/env/test/resources/config.edn
@@ -0,0 +1 @@
+{}
diff --git a/env/test/resources/logback.xml b/env/test/resources/logback.xml
new file mode 100644
index 0000000..8219609
--- /dev/null
+++ b/env/test/resources/logback.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+ UTF-8
+ %date{ISO8601} [%thread] %-5level %logger{36} - %msg %n
+
+
+
+ log/shapey-shifty.log
+
+ log/shapey-shifty.%d{yyyy-MM-dd}.%i.log
+
+ 100MB
+
+
+ 30
+
+
+ UTF-8
+ %date{ISO8601} [%thread] %-5level %logger{36} - %msg %n
+
+
+
+
+
+
+
+
+
+
diff --git a/project.clj b/project.clj
new file mode 100644
index 0000000..ff82eb6
--- /dev/null
+++ b/project.clj
@@ -0,0 +1,68 @@
+(defproject shapey-shifty "0.1.0-SNAPSHOT"
+
+ :description "FIXME: write description"
+ :url "http://example.com/FIXME"
+
+ :dependencies [[ch.qos.logback/logback-classic "1.2.3"]
+ [cheshire "5.9.0"]
+ [clojure.java-time "0.3.2"]
+ [cprop "0.1.15"]
+ [expound "0.8.3"]
+ [funcool/struct "1.4.0"]
+ [luminus-jetty "0.1.7"]
+ [luminus-transit "0.1.2"]
+ [luminus/ring-ttl-session "0.3.3"]
+ [markdown-clj "1.10.1"]
+ [metosin/muuntaja "0.6.6"]
+ [metosin/reitit "0.3.10"]
+ [metosin/ring-http-response "0.9.1"]
+ [mount "0.1.16"]
+ [nrepl "0.6.0"]
+ [org.clojure/clojure "1.10.1"]
+ [org.clojure/tools.cli "0.4.2"]
+ [org.clojure/tools.logging "0.5.0"]
+ [org.webjars.npm/bulma "0.8.0"]
+ [org.webjars.npm/material-icons "0.3.1"]
+ [org.webjars/webjars-locator "0.38"]
+ [ring-webjars "0.2.0"]
+ [ring/ring-core "1.8.0"]
+ [ring/ring-defaults "0.3.2"]
+ [selmer "1.12.18"]]
+
+ :min-lein-version "2.0.0"
+
+ :source-paths ["src/clj"]
+ :test-paths ["test/clj"]
+ :resource-paths ["resources"]
+ :target-path "target/%s/"
+ :main ^:skip-aot shapey-shifty.core
+
+ :plugins []
+
+ :profiles
+ {:uberjar {:omit-source true
+ :aot :all
+ :uberjar-name "shapey-shifty.jar"
+ :source-paths ["env/prod/clj"]
+ :resource-paths ["env/prod/resources"]}
+
+ :dev [:project/dev :profiles/dev]
+ :test [:project/dev :project/test :profiles/test]
+
+ :project/dev {:jvm-opts ["-Dconf=dev-config.edn"]
+ :dependencies [[pjstadig/humane-test-output "0.10.0"]
+ [prone "2019-07-08"]
+ [ring/ring-devel "1.8.0"]
+ [ring/ring-mock "0.4.0"]]
+ :plugins [[com.jakemccrary/lein-test-refresh "0.24.1"]
+ [jonase/eastwood "0.3.5"]]
+
+ :source-paths ["env/dev/clj"]
+ :resource-paths ["env/dev/resources"]
+ :repl-options {:init-ns user}
+ :injections [(require 'pjstadig.humane-test-output)
+ (pjstadig.humane-test-output/activate!)]}
+ :project/test {:jvm-opts ["-Dconf=test-config.edn"]
+ :resource-paths ["env/test/resources"]}
+ :profiles/dev {}
+ :profiles/test {}})
diff --git a/resources/docs/docs.md b/resources/docs/docs.md
new file mode 100644
index 0000000..a96b3ad
--- /dev/null
+++ b/resources/docs/docs.md
@@ -0,0 +1,100 @@
+
Congratulations, your Luminus site is ready!
+
+This page will help guide you through the first steps of building your site.
+
+#### Why are you seeing this page?
+
+The `home-routes` handler in the `shapey-shifty.routes.home` namespace
+defines the route that invokes the `home-page` function whenever an HTTP
+request is made to the `/` URI using the `GET` method.
+
+```
+(defn home-routes []
+ [""
+ {:middleware [middleware/wrap-csrf
+ middleware/wrap-formats]}
+ ["/" {:get home-page}]
+ ["/about" {:get about-page}]])
+```
+
+The `home-routes` are wrapped with two middleware functions. The first enables CSRF protection.
+The second takes care of serializing and deserializing various encoding formats, such as JSON.
+
+The `home-page` function will in turn call the `shapey-shifty.layout/render` function
+to render the HTML content:
+
+```
+(defn home-page [_]
+ (layout/render
+ "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))
+```
+
+The `render` function will render the `home.html` template found in the `resources/templates`
+folder using a parameter map containing the `:docs` key. This key points to the
+contents of the `resources/docs/docs.md` file containing these instructions.
+
+
+The HTML templates are written using [Selmer](https://github.com/yogthos/Selmer) templating engine.
+
+
+```
+
+
+ {{docs|markdown}}
+
+
+```
+
+learn more about HTML templating »
+
+
+
+#### Organizing the routes
+
+The routes are aggregated and wrapped with middleware in the `shapey-shifty.handler` namespace:
+
+```
+(mount/defstate app
+ :start
+ (middleware/wrap-base
+ (ring/ring-handler
+ (ring/router
+ [(home-routes)])
+ (ring/routes
+ (ring/create-resource-handler
+ {:path "/"})
+ (wrap-content-type
+ (wrap-webjars (constantly nil)))
+ (ring/create-default-handler
+ {:not-found
+ (constantly (error-page {:status 404, :title "404 - Page not found"}))
+ :method-not-allowed
+ (constantly (error-page {:status 405, :title "405 - Not allowed"}))
+ :not-acceptable
+ (constantly (error-page {:status 406, :title "406 - Not acceptable"}))})))))
+```
+
+The `app` definition groups all the routes in the application into a single handler.
+A default route group is added to handle the `404`, `405`, and `406` errors.
+
+learn more about routing »
+
+#### Managing your middleware
+
+Request middleware functions are located under the `shapey-shifty.middleware` namespace.
+
+This namespace is reserved for any custom middleware for the application. Some default middleware is
+already defined here. The middleware is assembled in the `wrap-base` function.
+
+Middleware used for development is placed in the `shapey-shifty.dev-middleware` namespace found in
+the `env/dev/clj/` source path.
+
+learn more about middleware »
+
+
+
+
+#### Need some help?
+
+Visit the [official documentation](http://www.luminusweb.net/docs) for examples
+on how to accomplish common tasks with Luminus. The `#luminus` channel on the [Clojurians Slack](http://clojurians.net/) and [Google Group](https://groups.google.com/forum/#!forum/luminusweb) are both great places to seek help and discuss projects with other users.
diff --git a/resources/html/about.html b/resources/html/about.html
new file mode 100644
index 0000000..aff3b2a
--- /dev/null
+++ b/resources/html/about.html
@@ -0,0 +1,4 @@
+{% extends "base.html" %}
+{% block content %}
+
+{% endblock %}
diff --git a/resources/html/base.html b/resources/html/base.html
new file mode 100644
index 0000000..d52d69f
--- /dev/null
+++ b/resources/html/base.html
@@ -0,0 +1,58 @@
+
+
+
+
+
+ Welcome to shapey-shifty
+
+
+ {% style "/assets/bulma/css/bulma.min.css" %}
+ {% style "/assets/material-icons/css/material-icons.min.css" %}
+
+ {% style "/css/screen.css" %}
+
+
+
+
+
+
+
+
+
+ {% block content %}
+ {% endblock %}
+
+
+
+
+
+
+
+ {% block page-scripts %}
+ {% endblock %}
+
+
diff --git a/resources/html/error.html b/resources/html/error.html
new file mode 100644
index 0000000..fd31cc5
--- /dev/null
+++ b/resources/html/error.html
@@ -0,0 +1,49 @@
+
+
+
+ Something Bad Happened
+
+
+ {% style "/assets/bulma/css/bulma.min.css" %}
+
+
+
+
+
+
Error: {{status}}
+
+ {% if title %}
+ {{title}}
+ {% endif %}
+ {% if message %}
+ {{message}}
+ {% endif %}
+
+
+
+
diff --git a/resources/html/home.html b/resources/html/home.html
new file mode 100644
index 0000000..c09946d
--- /dev/null
+++ b/resources/html/home.html
@@ -0,0 +1,6 @@
+{% extends "base.html" %}
+{% block content %}
+
+ {{docs|markdown}}
+
+{% endblock %}
diff --git a/resources/public/css/screen.css b/resources/public/css/screen.css
new file mode 100644
index 0000000..e90ddb8
--- /dev/null
+++ b/resources/public/css/screen.css
@@ -0,0 +1,35 @@
+html,
+body {
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
+}
+@font-face {
+ font-family: 'Material Icons';
+ font-style: normal;
+ font-weight: 400;
+ src: url(/assets/material-icons/iconfont/MaterialIcons-Regular.eot); /* For IE6-8 */
+ src: local('Material Icons'),
+ local('MaterialIcons-Regular'),
+ url(/assets/material-icons/iconfont/MaterialIcons-Regular.woff2) format('woff2'),
+ url(/assets/material-icons/iconfont/MaterialIcons-Regular.woff) format('woff'),
+ url(/assets/material-icons/iconfont/MaterialIcons-Regular.ttf) format('truetype');
+}
+.material-icons {
+ font-family: 'Material Icons';
+ font-weight: normal;
+ font-style: normal;
+ font-size: 24px; /* Preferred icon size */
+ display: inline-block;
+ line-height: 1;
+ text-transform: none;
+ letter-spacing: normal;
+ word-wrap: normal;
+ white-space: nowrap;
+ direction: ltr;
+ /* Support for all WebKit browsers. */
+ -webkit-font-smoothing: antialiased;
+ /* Support for Safari and Chrome. */
+ text-rendering: optimizeLegibility;
+ /* Support for Firefox. */
+ -moz-osx-font-smoothing: grayscale;
+}
+
diff --git a/resources/public/favicon.ico b/resources/public/favicon.ico
new file mode 100644
index 0000000..0e50cb2
Binary files /dev/null and b/resources/public/favicon.ico differ
diff --git a/resources/public/img/warning_clojure.png b/resources/public/img/warning_clojure.png
new file mode 100644
index 0000000..78d59e9
Binary files /dev/null and b/resources/public/img/warning_clojure.png differ
diff --git a/src/clj/shapey_shifty/config.clj b/src/clj/shapey_shifty/config.clj
new file mode 100644
index 0000000..53728f7
--- /dev/null
+++ b/src/clj/shapey_shifty/config.clj
@@ -0,0 +1,13 @@
+(ns shapey-shifty.config
+ (:require
+ [cprop.core :refer [load-config]]
+ [cprop.source :as source]
+ [mount.core :refer [args defstate]]))
+
+(defstate env
+ :start
+ (load-config
+ :merge
+ [(args)
+ (source/from-system-props)
+ (source/from-env)]))
diff --git a/src/clj/shapey_shifty/core.clj b/src/clj/shapey_shifty/core.clj
new file mode 100644
index 0000000..6a7113b
--- /dev/null
+++ b/src/clj/shapey_shifty/core.clj
@@ -0,0 +1,58 @@
+(ns shapey-shifty.core
+ (:require
+ [shapey-shifty.handler :as handler]
+ [shapey-shifty.nrepl :as nrepl]
+ [luminus.http-server :as http]
+ [shapey-shifty.config :refer [env]]
+ [clojure.tools.cli :refer [parse-opts]]
+ [clojure.tools.logging :as log]
+ [mount.core :as mount])
+ (:gen-class))
+
+;; log uncaught exceptions in threads
+(Thread/setDefaultUncaughtExceptionHandler
+ (reify Thread$UncaughtExceptionHandler
+ (uncaughtException [_ thread ex]
+ (log/error {:what :uncaught-exception
+ :exception ex
+ :where (str "Uncaught exception on" (.getName thread))}))))
+
+(def cli-options
+ [["-p" "--port PORT" "Port number"
+ :parse-fn #(Integer/parseInt %)]])
+
+(mount/defstate ^{:on-reload :noop} http-server
+ :start
+ (http/start
+ (-> env
+ (assoc :handler (handler/app))
+ (update :io-threads #(or % (* 2 (.availableProcessors (Runtime/getRuntime)))))
+ (update :port #(or (-> env :options :port) %))))
+ :stop
+ (http/stop http-server))
+
+(mount/defstate ^{:on-reload :noop} repl-server
+ :start
+ (when (env :nrepl-port)
+ (nrepl/start {:bind (env :nrepl-bind)
+ :port (env :nrepl-port)}))
+ :stop
+ (when repl-server
+ (nrepl/stop repl-server)))
+
+
+(defn stop-app []
+ (doseq [component (:stopped (mount/stop))]
+ (log/info component "stopped"))
+ (shutdown-agents))
+
+(defn start-app [args]
+ (doseq [component (-> args
+ (parse-opts cli-options)
+ mount/start-with-args
+ :started)]
+ (log/info component "started"))
+ (.addShutdownHook (Runtime/getRuntime) (Thread. stop-app)))
+
+(defn -main [& args]
+ (start-app args))
diff --git a/src/clj/shapey_shifty/handler.clj b/src/clj/shapey_shifty/handler.clj
new file mode 100644
index 0000000..f055f62
--- /dev/null
+++ b/src/clj/shapey_shifty/handler.clj
@@ -0,0 +1,35 @@
+(ns shapey-shifty.handler
+ (:require
+ [shapey-shifty.middleware :as middleware]
+ [shapey-shifty.layout :refer [error-page]]
+ [shapey-shifty.routes.home :refer [home-routes]]
+ [reitit.ring :as ring]
+ [ring.middleware.content-type :refer [wrap-content-type]]
+ [ring.middleware.webjars :refer [wrap-webjars]]
+ [shapey-shifty.env :refer [defaults]]
+ [mount.core :as mount]))
+
+(mount/defstate init-app
+ :start ((or (:init defaults) (fn [])))
+ :stop ((or (:stop defaults) (fn []))))
+
+(mount/defstate app-routes
+ :start
+ (ring/ring-handler
+ (ring/router
+ [(home-routes)])
+ (ring/routes
+ (ring/create-resource-handler
+ {:path "/"})
+ (wrap-content-type
+ (wrap-webjars (constantly nil)))
+ (ring/create-default-handler
+ {:not-found
+ (constantly (error-page {:status 404, :title "404 - Page not found"}))
+ :method-not-allowed
+ (constantly (error-page {:status 405, :title "405 - Not allowed"}))
+ :not-acceptable
+ (constantly (error-page {:status 406, :title "406 - Not acceptable"}))}))))
+
+(defn app []
+ (middleware/wrap-base #'app-routes))
diff --git a/src/clj/shapey_shifty/layout.clj b/src/clj/shapey_shifty/layout.clj
new file mode 100644
index 0000000..78c67f0
--- /dev/null
+++ b/src/clj/shapey_shifty/layout.clj
@@ -0,0 +1,39 @@
+(ns shapey-shifty.layout
+ (:require
+ [clojure.java.io]
+ [selmer.parser :as parser]
+ [selmer.filters :as filters]
+ [markdown.core :refer [md-to-html-string]]
+ [ring.util.http-response :refer [content-type ok]]
+ [ring.util.anti-forgery :refer [anti-forgery-field]]
+ [ring.middleware.anti-forgery :refer [*anti-forgery-token*]]
+ [ring.util.response]))
+
+(parser/set-resource-path! (clojure.java.io/resource "html"))
+(parser/add-tag! :csrf-field (fn [_ _] (anti-forgery-field)))
+(filters/add-filter! :markdown (fn [content] [:safe (md-to-html-string content)]))
+
+(defn render
+ "renders the HTML template located relative to resources/html"
+ [request template & [params]]
+ (content-type
+ (ok
+ (parser/render-file
+ template
+ (assoc params
+ :page template
+ :csrf-token *anti-forgery-token*)))
+ "text/html; charset=utf-8"))
+
+(defn error-page
+ "error-details should be a map containing the following keys:
+ :status - error status
+ :title - error title (optional)
+ :message - detailed error message (optional)
+
+ returns a response map with the error page as the body
+ and the status specified by the status key"
+ [error-details]
+ {:status (:status error-details)
+ :headers {"Content-Type" "text/html; charset=utf-8"}
+ :body (parser/render-file "error.html" error-details)})
diff --git a/src/clj/shapey_shifty/middleware.clj b/src/clj/shapey_shifty/middleware.clj
new file mode 100644
index 0000000..0f562b4
--- /dev/null
+++ b/src/clj/shapey_shifty/middleware.clj
@@ -0,0 +1,49 @@
+(ns shapey-shifty.middleware
+ (:require
+ [shapey-shifty.env :refer [defaults]]
+ [cheshire.generate :as cheshire]
+ [cognitect.transit :as transit]
+ [clojure.tools.logging :as log]
+ [shapey-shifty.layout :refer [error-page]]
+ [ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
+ [shapey-shifty.middleware.formats :as formats]
+ [muuntaja.middleware :refer [wrap-format wrap-params]]
+ [shapey-shifty.config :refer [env]]
+ [ring-ttl-session.core :refer [ttl-memory-store]]
+ [ring.middleware.defaults :refer [site-defaults wrap-defaults]])
+
+ )
+
+(defn wrap-internal-error [handler]
+ (fn [req]
+ (try
+ (handler req)
+ (catch Throwable t
+ (log/error t (.getMessage t))
+ (error-page {:status 500
+ :title "Something very bad has happened!"
+ :message "We've dispatched a team of highly trained gnomes to take care of the problem."})))))
+
+(defn wrap-csrf [handler]
+ (wrap-anti-forgery
+ handler
+ {:error-response
+ (error-page
+ {:status 403
+ :title "Invalid anti-forgery token"})}))
+
+
+(defn wrap-formats [handler]
+ (let [wrapped (-> handler wrap-params (wrap-format formats/instance))]
+ (fn [request]
+ ;; disable wrap-formats for websockets
+ ;; since they're not compatible with this middleware
+ ((if (:websocket? request) handler wrapped) request))))
+
+(defn wrap-base [handler]
+ (-> ((:middleware defaults) handler)
+ (wrap-defaults
+ (-> site-defaults
+ (assoc-in [:security :anti-forgery] false)
+ (assoc-in [:session :store] (ttl-memory-store (* 60 30)))))
+ wrap-internal-error))
diff --git a/src/clj/shapey_shifty/middleware/formats.clj b/src/clj/shapey_shifty/middleware/formats.clj
new file mode 100644
index 0000000..42ab67b
--- /dev/null
+++ b/src/clj/shapey_shifty/middleware/formats.clj
@@ -0,0 +1,15 @@
+(ns shapey-shifty.middleware.formats
+ (:require
+ [cognitect.transit :as transit]
+ [luminus-transit.time :as time]
+ [muuntaja.core :as m]))
+
+(def instance
+ (m/create
+ (-> m/default-options
+ (update-in
+ [:formats "application/transit+json" :decoder-opts]
+ (partial merge time/time-deserialization-handlers))
+ (update-in
+ [:formats "application/transit+json" :encoder-opts]
+ (partial merge time/time-serialization-handlers)))))
diff --git a/src/clj/shapey_shifty/nrepl.clj b/src/clj/shapey_shifty/nrepl.clj
new file mode 100644
index 0000000..8dda084
--- /dev/null
+++ b/src/clj/shapey_shifty/nrepl.clj
@@ -0,0 +1,27 @@
+(ns shapey-shifty.nrepl
+ (:require
+ [nrepl.server :as nrepl]
+ [clojure.tools.logging :as log]))
+
+(defn start
+ "Start a network repl for debugging on specified port followed by
+ an optional parameters map. The :bind, :transport-fn, :handler,
+ :ack-port and :greeting-fn will be forwarded to
+ clojure.tools.nrepl.server/start-server as they are."
+ [{:keys [port bind transport-fn handler ack-port greeting-fn]}]
+ (try
+ (log/info "starting nREPL server on port" port)
+ (nrepl/start-server :port port
+ :bind bind
+ :transport-fn transport-fn
+ :handler handler
+ :ack-port ack-port
+ :greeting-fn greeting-fn)
+
+ (catch Throwable t
+ (log/error t "failed to start nREPL")
+ (throw t))))
+
+(defn stop [server]
+ (nrepl/stop-server server)
+ (log/info "nREPL server stopped"))
diff --git a/src/clj/shapey_shifty/routes/home.clj b/src/clj/shapey_shifty/routes/home.clj
new file mode 100644
index 0000000..feb8865
--- /dev/null
+++ b/src/clj/shapey_shifty/routes/home.clj
@@ -0,0 +1,21 @@
+(ns shapey-shifty.routes.home
+ (:require
+ [shapey-shifty.layout :as layout]
+ [clojure.java.io :as io]
+ [shapey-shifty.middleware :as middleware]
+ [ring.util.response]
+ [ring.util.http-response :as response]))
+
+(defn home-page [request]
+ (layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))
+
+(defn about-page [request]
+ (layout/render request "about.html"))
+
+(defn home-routes []
+ [""
+ {:middleware [middleware/wrap-csrf
+ middleware/wrap-formats]}
+ ["/" {:get home-page}]
+ ["/about" {:get about-page}]])
+
diff --git a/test-config.edn b/test-config.edn
new file mode 100644
index 0000000..42b7146
--- /dev/null
+++ b/test-config.edn
@@ -0,0 +1,6 @@
+;; WARNING
+;; The test-config.edn file is used for local environment variables, such as database credentials.
+;; This file is listed in .gitignore and will be excluded from version control by Git.
+
+{:port 3000
+ }
diff --git a/test/clj/shapey_shifty/test/handler.clj b/test/clj/shapey_shifty/test/handler.clj
new file mode 100644
index 0000000..02506e3
--- /dev/null
+++ b/test/clj/shapey_shifty/test/handler.clj
@@ -0,0 +1,27 @@
+(ns shapey-shifty.test.handler
+ (:require
+ [clojure.test :refer :all]
+ [ring.mock.request :refer :all]
+ [shapey-shifty.handler :refer :all]
+ [shapey-shifty.middleware.formats :as formats]
+ [muuntaja.core :as m]
+ [mount.core :as mount]))
+
+(defn parse-json [body]
+ (m/decode formats/instance "application/json" body))
+
+(use-fixtures
+ :once
+ (fn [f]
+ (mount/start #'shapey-shifty.config/env
+ #'shapey-shifty.handler/app-routes)
+ (f)))
+
+(deftest test-app
+ (testing "main route"
+ (let [response ((app) (request :get "/"))]
+ (is (= 200 (:status response)))))
+
+ (testing "not-found route"
+ (let [response ((app) (request :get "/invalid"))]
+ (is (= 404 (:status response))))))