4 | {% endblock %}
5 |
--------------------------------------------------------------------------------
/multi-client-ws-http-kit/src/cljc/multi_client_ws_http_kit/validation.cljc:
--------------------------------------------------------------------------------
1 | (ns multi-client-ws-http-kit.validation
2 | (:require [struct.core :as st]))
3 |
--------------------------------------------------------------------------------
/multi-client-ws-immutant/src/cljc/multi_client_ws_immutant/validation.cljc:
--------------------------------------------------------------------------------
1 | (ns multi-client-ws-immutant.validation
2 | (:require [struct.core :as st]))
3 |
--------------------------------------------------------------------------------
/file-upload-progress/resources/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/file-upload-progress/resources/public/favicon.ico
--------------------------------------------------------------------------------
/guestbook/resources/public/img/warning_clojure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/guestbook/resources/public/img/warning_clojure.png
--------------------------------------------------------------------------------
/multi-client-ws-aleph/resources/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/multi-client-ws-aleph/resources/public/favicon.ico
--------------------------------------------------------------------------------
/multi-client-ws-http-kit/resources/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/multi-client-ws-http-kit/resources/public/favicon.ico
--------------------------------------------------------------------------------
/multi-client-ws-immutant/resources/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/multi-client-ws-immutant/resources/public/favicon.ico
--------------------------------------------------------------------------------
/guestbook-cljs/env/dev/resources/config.edn:
--------------------------------------------------------------------------------
1 | {:dev true
2 | :port 3000
3 | ;; when :nrepl-port is set the application starts the nREPL server on load
4 | :nrepl-port 7000}
5 |
--------------------------------------------------------------------------------
/guestbook-cljs/env/test/resources/config.edn:
--------------------------------------------------------------------------------
1 | {:test true
2 | :port 3001
3 | :nrepl-port 7001} ;; when :nrepl-port is set the application starts the nREPL server on load
4 |
--------------------------------------------------------------------------------
/guestbook-datomic/resources/public/img/warning_clojure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/guestbook-datomic/resources/public/img/warning_clojure.png
--------------------------------------------------------------------------------
/guestbook-sente/resources/public/img/warning_clojure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/guestbook-sente/resources/public/img/warning_clojure.png
--------------------------------------------------------------------------------
/file-upload-progress/env/dev/resources/config.edn:
--------------------------------------------------------------------------------
1 | {:dev true
2 | :port 3000
3 | ;; when :nrepl-port is set the application starts the nREPL server on load
4 | :nrepl-port 7000}
5 |
--------------------------------------------------------------------------------
/guestbook/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-alpine
2 |
3 | COPY target/uberjar/guestbook.jar /guestbook/app.jar
4 |
5 | EXPOSE 3000
6 |
7 | CMD ["java", "-jar", "/guestbook/app.jar"]
8 |
--------------------------------------------------------------------------------
/file-upload-progress/env/test/resources/config.edn:
--------------------------------------------------------------------------------
1 | {:dev true
2 | :port 3000
3 | ;; when :nrepl-port is set the application starts the nREPL server on load
4 | :nrepl-port 7000}
5 |
--------------------------------------------------------------------------------
/file-upload-progress/resources/public/img/warning_clojure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/file-upload-progress/resources/public/img/warning_clojure.png
--------------------------------------------------------------------------------
/guestbook-cljs/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /lib
3 | /classes
4 | /checkouts
5 | pom.xml
6 | *.jar
7 | *.class
8 | /.lein-*
9 | profiles.clj
10 | /.env
11 | .nrepl-port
12 | /log
13 |
--------------------------------------------------------------------------------
/multi-client-ws-aleph/resources/public/img/warning_clojure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/multi-client-ws-aleph/resources/public/img/warning_clojure.png
--------------------------------------------------------------------------------
/file-upload-progress/resources/templates/about.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% block content %}
3 |
4 | {% endblock %}
5 |
--------------------------------------------------------------------------------
/multi-client-ws-http-kit/resources/public/img/warning_clojure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/multi-client-ws-http-kit/resources/public/img/warning_clojure.png
--------------------------------------------------------------------------------
/multi-client-ws-immutant/resources/public/img/warning_clojure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luminus-framework/examples/HEAD/multi-client-ws-immutant/resources/public/img/warning_clojure.png
--------------------------------------------------------------------------------
/reporting-example/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /lib
3 | /classes
4 | /checkouts
5 | pom.xml
6 | *.jar
7 | *.class
8 | /.lein-*
9 | profiles.clj
10 | /.env
11 | .nrepl-port
12 | /log
13 |
--------------------------------------------------------------------------------
/swagger-service/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /lib
3 | /classes
4 | /checkouts
5 | pom.xml
6 | *.jar
7 | *.class
8 | /.lein-*
9 | profiles.clj
10 | /.env
11 | .nrepl-port
12 | /log
13 |
--------------------------------------------------------------------------------
/reporting-example/resources/migrations/201504171229-add-users-table.up.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE employee
2 | (name VARCHAR(50),
3 | occupation VARCHAR(50),
4 | place VARCHAR(50),
5 | country VARCHAR(50));
6 |
--------------------------------------------------------------------------------
/guestbook-sente/env/prod/cljs/guestbook/app.cljs:
--------------------------------------------------------------------------------
1 | (ns guestbook.app
2 | (:require [guestbook.core :as core]))
3 |
4 | ;;ignore println statements in prod
5 | (set! *print-fn* (fn [& _]))
6 |
7 | (core/init!)
8 |
--------------------------------------------------------------------------------
/multi-client-ws-http-kit/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /lib
3 | /classes
4 | /checkouts
5 | pom.xml
6 | *.jar
7 | *.class
8 | /.lein-*
9 | profiles.clj
10 | /.env
11 | .nrepl-port
12 | /node_modules
13 | /log
14 |
--------------------------------------------------------------------------------
/multi-client-ws-immutant/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /lib
3 | /classes
4 | /checkouts
5 | pom.xml
6 | *.jar
7 | *.class
8 | /.lein-*
9 | profiles.clj
10 | /.env
11 | .nrepl-port
12 | /node_modules
13 | /log
14 |
--------------------------------------------------------------------------------
/guestbook-sente/resources/migrations/20190317085139-add-users-table.up.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE guestbook
2 | (id INTEGER PRIMARY KEY AUTO_INCREMENT,
3 | name VARCHAR(30),
4 | message VARCHAR(200),
5 | timestamp TIMESTAMP);
6 |
--------------------------------------------------------------------------------
/guestbook-sente/test/cljs/guestbook/doo_runner.cljs:
--------------------------------------------------------------------------------
1 | (ns guestbook.doo-runner
2 | (:require [doo.runner :refer-macros [doo-tests]]
3 | [guestbook.core-test]))
4 |
5 | (doo-tests 'guestbook.core-test)
6 |
7 |
--------------------------------------------------------------------------------
/guestbook/resources/migrations/20190317085139-add-users-table.up.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE guestbook
2 | (id INTEGER PRIMARY KEY AUTO_INCREMENT,
3 | name VARCHAR(30),
4 | message VARCHAR(200),
5 | timestamp TIMESTAMP(7));
6 |
--------------------------------------------------------------------------------
/guestbook-sente/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /lib
3 | /classes
4 | /checkouts
5 | pom.xml
6 | dev-config.edn
7 | test-config.edn
8 | *.jar
9 | *.class
10 | /.lein-*
11 | profiles.clj
12 | /.env
13 | .nrepl-port
14 | /log
15 |
--------------------------------------------------------------------------------
/file-upload-progress/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /lib
3 | /classes
4 | /checkouts
5 | pom.xml
6 | dev-config.edn
7 | test-config.edn
8 | *.jar
9 | *.class
10 | /.lein-*
11 | profiles.clj
12 | /.env
13 | .nrepl-port
14 | /log
15 |
--------------------------------------------------------------------------------
/guestbook-datomic/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /lib
3 | /classes
4 | /checkouts
5 | pom.xml
6 | dev-config.edn
7 | test-config.edn
8 | *.jar
9 | *.class
10 | /.lein-*
11 | profiles.clj
12 | /.env
13 | .nrepl-port
14 | /log
15 |
--------------------------------------------------------------------------------
/guestbook-datomic/env/prod/cljs/guestbook_datomic/app.cljs:
--------------------------------------------------------------------------------
1 | (ns guestbook-datomic.app
2 | (:require [guestbook-datomic.core :as core]))
3 |
4 | ;;ignore println statements in prod
5 | (set! *print-fn* (fn [& _]))
6 |
7 | (core/init!)
8 |
--------------------------------------------------------------------------------
/multi-client-ws-http-kit/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-alpine
2 |
3 | COPY target/uberjar/multi-client-ws-http-kit.jar /multi-client-ws-http-kit/app.jar
4 |
5 | EXPOSE 3000
6 |
7 | CMD ["java", "-jar", "/multi-client-ws-http-kit/app.jar"]
8 |
--------------------------------------------------------------------------------
/multi-client-ws-immutant/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-alpine
2 |
3 | COPY target/uberjar/multi-client-ws-immutant.jar /multi-client-ws-immutant/app.jar
4 |
5 | EXPOSE 3000
6 |
7 | CMD ["java", "-jar", "/multi-client-ws-immutant/app.jar"]
8 |
--------------------------------------------------------------------------------
/guestbook/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /lib
3 | /classes
4 | /checkouts
5 | pom.xml
6 | dev-config.edn
7 | test-config.edn
8 | *.jar
9 | *.class
10 | /.lein-*
11 | profiles.clj
12 | /.env
13 | .nrepl-port
14 |
15 | /node_modules
16 | /log
17 |
--------------------------------------------------------------------------------
/guestbook-datomic/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM java:8-alpine
2 | MAINTAINER Your Name this is the story of guestbook... work in progress
12 | {% endblock %} 13 | -------------------------------------------------------------------------------- /multi-client-ws-http-kit/src/clj/multi_client_ws_http_kit/middleware/formats.clj: -------------------------------------------------------------------------------- 1 | (ns multi-client-ws-http-kit.middleware.formats 2 | (:require 3 | [cognitect.transit :as transit] 4 | [luminus-transit.time :as time] 5 | [muuntaja.core :as m])) 6 | 7 | (def instance 8 | (m/create 9 | (-> m/default-options 10 | (update-in 11 | [:formats "application/transit+json" :decoder-opts] 12 | (partial merge time/time-deserialization-handlers)) 13 | (update-in 14 | [:formats "application/transit+json" :encoder-opts] 15 | (partial merge time/time-serialization-handlers))))) 16 | -------------------------------------------------------------------------------- /multi-client-ws-immutant/src/clj/multi_client_ws_immutant/middleware/formats.clj: -------------------------------------------------------------------------------- 1 | (ns multi-client-ws-immutant.middleware.formats 2 | (:require 3 | [cognitect.transit :as transit] 4 | [luminus-transit.time :as time] 5 | [muuntaja.core :as m])) 6 | 7 | (def instance 8 | (m/create 9 | (-> m/default-options 10 | (update-in 11 | [:formats "application/transit+json" :decoder-opts] 12 | (partial merge time/time-deserialization-handlers)) 13 | (update-in 14 | [:formats "application/transit+json" :encoder-opts] 15 | (partial merge time/time-serialization-handlers))))) 16 | -------------------------------------------------------------------------------- /reporting-example/resources/templates/about.html: -------------------------------------------------------------------------------- 1 | 9 | {% extends "base.html" %} 10 | {% block content %} 11 |this is the story of reporting-example... work in progress
12 | {% endblock %} 13 | -------------------------------------------------------------------------------- /guestbook-cljs/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 9 | {% extends "base.html" %} 10 | {% block content %} 11 | 12 | 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /guestbook-datomic/dev-config.edn: -------------------------------------------------------------------------------- 1 | ;; WARNING 2 | ;; The dev-config.edn file is used for local environment variables, such as database credentials. 3 | ;; This file is listed in .gitignore and will be excluded from version control by Git. 4 | 5 | {:dev true 6 | :port 3000 7 | ;; when :nrepl-port is set the application starts the nREPL server on load 8 | :nrepl-port 7000 9 | 10 | ; set your dev database connection URL here 11 | ; :database-url "datomic:free://localhost:4334/guestbook_datomic_dev" 12 | ; Don't forget you can also use the datomic mem db which can be useful when developing 13 | :database-url "datomic:mem://guestbook_datomic_dev" 14 | } 15 | -------------------------------------------------------------------------------- /swagger-service/env/prod/cljs/swagger_service/prod.cljs: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns swagger-service.app 10 | (:require [swagger-service.core :as core])) 11 | 12 | ;;ignore println statements in prod 13 | (set! *print-fn* (fn [& _])) 14 | 15 | (core/init!) 16 | -------------------------------------------------------------------------------- /guestbook-datomic/env/dev/clj/user.clj: -------------------------------------------------------------------------------- 1 | (ns user 2 | (:require [guestbook-datomic.config :refer [env]] 3 | [clojure.spec.alpha :as s] 4 | [expound.alpha :as expound] 5 | [mount.core :as mount] 6 | [guestbook-datomic.figwheel :refer [start-fw stop-fw cljs]] 7 | [guestbook-datomic.core :refer [start-app]])) 8 | 9 | (alter-var-root #'s/*explain-out* (constantly expound/printer)) 10 | 11 | (defn start [] 12 | (mount/start-without #'guestbook-datomic.core/repl-server)) 13 | 14 | (defn stop [] 15 | (mount/stop-except #'guestbook-datomic.core/repl-server)) 16 | 17 | (defn restart [] 18 | (stop) 19 | (start)) 20 | 21 | 22 | -------------------------------------------------------------------------------- /swagger-service/test/cljs/swagger_service/doo_runner.cljs: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns swagger-service.doo-runner 10 | (:require [doo.runner :refer-macros [doo-tests]] 11 | [swagger-service.core-test])) 12 | 13 | (doo-tests 'swagger-service.core-test) 14 | 15 | -------------------------------------------------------------------------------- /guestbook-cljs/env/prod/clj/guestbook/env.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns guestbook.env 10 | (:require [clojure.tools.logging :as log])) 11 | 12 | (def defaults 13 | {:init 14 | (fn [] 15 | (log/info "\n-=[guestbook started successfully]=-")) 16 | :middleware identity}) 17 | -------------------------------------------------------------------------------- /swagger-service/env/prod/clj/swagger_service/config.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns swagger-service.config 10 | (:require [clojure.tools.logging :as log])) 11 | 12 | (def defaults 13 | {:init 14 | (fn [] 15 | (log/info "\n-=[swagger-service started successfully]=-")) 16 | :middleware identity}) 17 | -------------------------------------------------------------------------------- /reporting-example/env/prod/clj/reporting_example/config.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns reporting-example.config 10 | (:require [clojure.tools.logging :as log])) 11 | 12 | (def defaults 13 | {:init 14 | (fn [] 15 | (log/info "\n-=[reporting-example started successfully]=-")) 16 | :middleware identity}) 17 | -------------------------------------------------------------------------------- /reporting-example/resources/public/css/screen.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 4 | height: 100%; 5 | } 6 | .navbar { 7 | margin-bottom: 10px; 8 | } 9 | .navbar-brand { 10 | float: none; 11 | } 12 | .navbar-nav .nav-item { 13 | float: none; 14 | } 15 | .navbar-divider, 16 | .navbar-nav .nav-item+.nav-item, 17 | .navbar-nav .nav-link + .nav-link { 18 | margin-left: 0; 19 | } 20 | @media (min-width: 34em) { 21 | .navbar-brand { 22 | float: left; 23 | } 24 | .navbar-nav .nav-item { 25 | float: left; 26 | } 27 | .navbar-divider, 28 | .navbar-nav .nav-item+.nav-item, 29 | .navbar-nav .nav-link + .nav-link { 30 | margin-left: 1rem; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /guestbook-datomic/test/clj/guestbook_datomic/test/handler.clj: -------------------------------------------------------------------------------- 1 | (ns guestbook-datomic.test.handler 2 | (:require [clojure.test :refer :all] 3 | [ring.mock.request :refer :all] 4 | [guestbook-datomic.handler :refer :all] 5 | [mount.core :as mount])) 6 | 7 | (use-fixtures 8 | :once 9 | (fn [f] 10 | (mount/start #'guestbook-datomic.config/env 11 | #'guestbook-datomic.handler/app) 12 | (f))) 13 | 14 | (deftest test-app 15 | (testing "main route" 16 | (let [response (app (request :get "/"))] 17 | (is (= 200 (:status response))))) 18 | 19 | (testing "not-found route" 20 | (let [response (app (request :get "/invalid"))] 21 | (is (= 404 (:status response)))))) 22 | -------------------------------------------------------------------------------- /guestbook/Capstanfile: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Name of the base image. Capstan will download this automatically from 4 | # Cloudius S3 repository. 5 | # 6 | #base: cloudius/osv 7 | base: cloudius/osv-openjdk8 8 | 9 | # 10 | # The command line passed to OSv to start up the application. 11 | # 12 | cmdline: /java.so -jar /guestbook/app.jar 13 | 14 | # 15 | # The command to use to build the application. 16 | # You can use any build tool/command (make/rake/lein/boot) - this runs locally on your machine 17 | # 18 | # For Leiningen, you can use: 19 | #build: lein uberjar 20 | # For Boot, you can use: 21 | #build: boot build 22 | 23 | # 24 | # List of files that are included in the generated image. 25 | # 26 | files: 27 | /guestbook/app.jar: ./target/uberjar/guestbook.jar 28 | 29 | -------------------------------------------------------------------------------- /swagger-service/test/cljs/swagger_service/core_test.cljs: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns swagger-service.core-test 10 | (:require [cljs.test :refer-macros [is are deftest testing use-fixtures]] 11 | [reagent.core :as reagent :refer [atom]] 12 | [swagger-service.core :as rc])) 13 | 14 | (deftest test-home 15 | (is (= true true))) 16 | 17 | -------------------------------------------------------------------------------- /guestbook-cljs/env/dev/clj/user.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns user 10 | (:require [mount.core :as mount] 11 | guestbook.core)) 12 | 13 | (defn start [] 14 | (mount/start-without #'guestbook.core/repl-server)) 15 | 16 | (defn stop [] 17 | (mount/stop-except #'guestbook.core/repl-server)) 18 | 19 | (defn restart [] 20 | (stop) 21 | (start)) 22 | 23 | 24 | -------------------------------------------------------------------------------- /guestbook-datomic/Capstanfile: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Name of the base image. Capstan will download this automatically from 4 | # Cloudius S3 repository. 5 | # 6 | #base: cloudius/osv 7 | base: cloudius/osv-openjdk8 8 | 9 | # 10 | # The command line passed to OSv to start up the application. 11 | # 12 | cmdline: /java.so -jar /guestbook-datomic/app.jar 13 | 14 | # 15 | # The command to use to build the application. 16 | # You can use any build tool/command (make/rake/lein/boot) - this runs locally on your machine 17 | # 18 | # For Leiningen, you can use: 19 | #build: lein uberjar 20 | # For Boot, you can use: 21 | #build: boot build 22 | 23 | # 24 | # List of files that are included in the generated image. 25 | # 26 | files: 27 | /guestbook-datomic/app.jar: ./target/uberjar/guestbook-datomic.jar 28 | 29 | -------------------------------------------------------------------------------- /guestbook-sente/src/clj/guestbook/routes/home.clj: -------------------------------------------------------------------------------- 1 | (ns guestbook.routes.home 2 | (:require 3 | [guestbook.db.core :as db] 4 | [guestbook.layout :as layout] 5 | [guestbook.routes.ws :as ws] 6 | [clojure.java.io :as io] 7 | [guestbook.middleware :as middleware] 8 | [ring.util.http-response :as response])) 9 | 10 | (defn home-page [request] 11 | (layout/render request "home.html")) 12 | 13 | (defn get-messages [_] 14 | (response/ok (db/get-messages))) 15 | 16 | (defn home-routes [] 17 | ["" 18 | {:middleware [middleware/wrap-csrf 19 | middleware/wrap-formats]} 20 | ["/" {:get home-page}] 21 | ["/messages" {:get get-messages}] 22 | ["/ws" {:get (:ajax-get-or-ws-handshake-fn ws/connection) 23 | :post (:ajax-post-fn ws/connection)}]]) 24 | -------------------------------------------------------------------------------- /file-upload-progress/Capstanfile: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Name of the base image. Capstan will download this automatically from 4 | # Cloudius S3 repository. 5 | # 6 | #base: cloudius/osv 7 | base: cloudius/osv-openjdk8 8 | 9 | # 10 | # The command line passed to OSv to start up the application. 11 | # 12 | cmdline: /java.so -jar /file-upload-progress/app.jar 13 | 14 | # 15 | # The command to use to build the application. 16 | # You can use any build tool/command (make/rake/lein/boot) - this runs locally on your machine 17 | # 18 | # For Leiningen, you can use: 19 | #build: lein uberjar 20 | # For Boot, you can use: 21 | #build: boot build 22 | 23 | # 24 | # List of files that are included in the generated image. 25 | # 26 | files: 27 | /file-upload-progress/app.jar: ./target/uberjar/file-upload-progress.jar 28 | 29 | -------------------------------------------------------------------------------- /file-upload-progress/resources/public/css/screen.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 4 | height: 100%; 5 | } 6 | .navbar { 7 | margin-bottom: 10px; 8 | border-radius: 0px; 9 | } 10 | .navbar-brand { 11 | float: none; 12 | } 13 | .navbar-nav .nav-item { 14 | float: none; 15 | } 16 | .navbar-divider, 17 | .navbar-nav .nav-item+.nav-item, 18 | .navbar-nav .nav-link + .nav-link { 19 | margin-left: 0; 20 | } 21 | @media (min-width: 34em) { 22 | .navbar-brand { 23 | float: left; 24 | } 25 | .navbar-nav .nav-item { 26 | float: left; 27 | } 28 | .navbar-divider, 29 | .navbar-nav .nav-item+.nav-item, 30 | .navbar-nav .nav-link + .nav-link { 31 | margin-left: 1rem; 32 | } 33 | } 34 | .row { 35 | margin-bottom: 20px; 36 | } 37 | -------------------------------------------------------------------------------- /guestbook/resources/sql/queries.sql: -------------------------------------------------------------------------------- 1 | -- :name create-user! :! :n 2 | -- :doc creates a new user record 3 | INSERT INTO users 4 | (id, first_name, last_name, email, pass) 5 | VALUES (:id, :first_name, :last_name, :email, :pass) 6 | 7 | -- :name update-user! :! :n 8 | -- :doc update an existing user record 9 | UPDATE users 10 | SET first_name = :first_name, last_name = :last_name, email = :email 11 | WHERE id = :id 12 | 13 | -- :name get-user :? :1 14 | -- :doc retrieve a user given the id. 15 | SELECT * FROM users 16 | WHERE id = :id 17 | 18 | -- :name save-message! :! :n 19 | -- :doc creates a new message 20 | INSERT INTO guestbook 21 | (name, message, timestamp) 22 | VALUES (:name, :message, :timestamp) 23 | 24 | -- :name get-messages :? :* 25 | -- :doc selects all available messages 26 | SELECT * FROM guestbook -------------------------------------------------------------------------------- /guestbook-cljs/env/dev/clj/guestbook/dev_middleware.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns guestbook.dev-middleware 10 | (:require [ring.middleware.reload :refer [wrap-reload]] 11 | [selmer.middleware :refer [wrap-error-page]] 12 | [prone.middleware :refer [wrap-exceptions]])) 13 | 14 | (defn wrap-dev [handler] 15 | (-> handler 16 | wrap-reload 17 | wrap-error-page 18 | wrap-exceptions)) 19 | -------------------------------------------------------------------------------- /guestbook-sente/test/clj/guestbook/test/handler.clj: -------------------------------------------------------------------------------- 1 | (ns guestbook.test.handler 2 | (:require 3 | [clojure.test :refer :all] 4 | [ring.mock.request :refer :all] 5 | [guestbook.handler :refer :all] 6 | [guestbook.middleware.formats :as formats] 7 | [muuntaja.core :as m] 8 | [mount.core :as mount])) 9 | 10 | (defn parse-json [body] 11 | (m/decode formats/instance "application/json" body)) 12 | 13 | (use-fixtures 14 | :once 15 | (fn [f] 16 | (mount/start #'guestbook.config/env 17 | #'guestbook.handler/app) 18 | (f))) 19 | 20 | (deftest test-app 21 | (testing "main route" 22 | (let [response (app (request :get "/"))] 23 | (is (= 200 (:status response))))) 24 | 25 | (testing "not-found route" 26 | (let [response (app (request :get "/invalid"))] 27 | (is (= 404 (:status response)))))) 28 | -------------------------------------------------------------------------------- /swagger-service/env/dev/clj/swagger_service/dev_middleware.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns swagger-service.dev-middleware 10 | (:require [ring.middleware.reload :refer [wrap-reload]] 11 | [selmer.middleware :refer [wrap-error-page]] 12 | [prone.middleware :refer [wrap-exceptions]])) 13 | 14 | (defn wrap-dev [handler] 15 | (-> handler 16 | wrap-reload 17 | wrap-error-page 18 | wrap-exceptions)) 19 | -------------------------------------------------------------------------------- /guestbook-cljs/env/dev/clj/guestbook/env.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns guestbook.env 10 | (:require [selmer.parser :as parser] 11 | [clojure.tools.logging :as log] 12 | [guestbook.dev-middleware :refer [wrap-dev]])) 13 | 14 | (def defaults 15 | {:init 16 | (fn [] 17 | (parser/cache-off!) 18 | (log/info "\n-=[guestbook started successfully using the development profile]=-")) 19 | :middleware wrap-dev}) 20 | -------------------------------------------------------------------------------- /guestbook/test/clj/guestbook/test/handler.clj: -------------------------------------------------------------------------------- 1 | (ns guestbook.test.handler 2 | (:require 3 | [clojure.test :refer :all] 4 | [ring.mock.request :refer :all] 5 | [guestbook.handler :refer :all] 6 | [guestbook.middleware.formats :as formats] 7 | [muuntaja.core :as m] 8 | [mount.core :as mount])) 9 | 10 | (defn parse-json [body] 11 | (m/decode formats/instance "application/json" body)) 12 | 13 | (use-fixtures 14 | :once 15 | (fn [f] 16 | (mount/start #'guestbook.config/env 17 | #'guestbook.handler/app-routes) 18 | (f))) 19 | 20 | (deftest test-app 21 | (testing "main route" 22 | (let [response ((app) (request :get "/"))] 23 | (is (= 200 (:status response))))) 24 | 25 | (testing "not-found route" 26 | (let [response ((app) (request :get "/invalid"))] 27 | (is (= 404 (:status response)))))) 28 | -------------------------------------------------------------------------------- /reporting-example/env/dev/clj/reporting_example/dev_middleware.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns reporting-example.dev-middleware 10 | (:require [ring.middleware.reload :refer [wrap-reload]] 11 | [selmer.middleware :refer [wrap-error-page]] 12 | [prone.middleware :refer [wrap-exceptions]])) 13 | 14 | (defn wrap-dev [handler] 15 | (-> handler 16 | wrap-reload 17 | wrap-error-page 18 | wrap-exceptions)) 19 | -------------------------------------------------------------------------------- /file-upload-progress/src/clj/file_upload_progress/routes/home.clj: -------------------------------------------------------------------------------- 1 | (ns file-upload-progress.routes.home 2 | (:require [file-upload-progress.layout :as layout] 3 | [compojure.core :refer [defroutes GET POST]] 4 | [ring.util.http-response :as response] 5 | [clojure.java.io :as io])) 6 | 7 | (defn home-page [] 8 | (layout/render 9 | "home.html" {:docs (-> "docs/docs.md" io/resource slurp)})) 10 | 11 | (defn about-page [] 12 | (layout/render "about.html")) 13 | 14 | (defn upload-hanlder [{:keys [filename content-type tempfile size]}] 15 | (io/copy (io/file tempfile) (io/file filename)) 16 | (io/delete-file (.getAbsolutePath tempfile)) 17 | (response/ok {:status :ok})) 18 | 19 | (defroutes home-routes 20 | (GET "/" [] (home-page)) 21 | (GET "/about" [] (about-page)) 22 | (POST "/upload" [file] (upload-hanlder file))) 23 | -------------------------------------------------------------------------------- /guestbook-cljs/src/clj/guestbook/config.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns guestbook.config 10 | (:require [cprop.core :refer [load-config]] 11 | [cprop.source :as source] 12 | [mount.core :refer [args defstate]])) 13 | 14 | (defstate env :start (load-config 15 | :merge 16 | [(args) 17 | (source/from-system-props) 18 | (source/from-env)])) 19 | -------------------------------------------------------------------------------- /swagger-service/env/dev/clj/swagger_service/config.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns swagger-service.config 10 | (:require [selmer.parser :as parser] 11 | [clojure.tools.logging :as log] 12 | [swagger-service.dev-middleware :refer [wrap-dev]])) 13 | 14 | (def defaults 15 | {:init 16 | (fn [] 17 | (parser/cache-off!) 18 | (log/info "\n-=[swagger-service started successfully using the development profile]=-")) 19 | :middleware wrap-dev}) 20 | -------------------------------------------------------------------------------- /reporting-example/env/dev/clj/reporting_example/config.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns reporting-example.config 10 | (:require [selmer.parser :as parser] 11 | [clojure.tools.logging :as log] 12 | [reporting-example.dev-middleware :refer [wrap-dev]])) 13 | 14 | (def defaults 15 | {:init 16 | (fn [] 17 | (parser/cache-off!) 18 | (log/info "\n-=[reporting-example started successfully using the development profile]=-")) 19 | :middleware wrap-dev}) 20 | -------------------------------------------------------------------------------- /reporting-example/env/dev/clj/user.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns user 10 | (:require [reporting-example.handler :refer [app init destroy]] 11 | [luminus.http-server :as http] 12 | [config.core :refer [env]])) 13 | 14 | (defn start [] 15 | (http/start {:handler app 16 | :init init 17 | :port (:port env)})) 18 | 19 | (defn stop [] 20 | (http/stop destroy)) 21 | 22 | (defn restart [] 23 | (stop) 24 | (start)) 25 | 26 | 27 | -------------------------------------------------------------------------------- /swagger-service/env/dev/clj/user.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns user 10 | (:require [swagger-service.handler :refer [app init destroy]] 11 | [luminus.http-server :as http] 12 | [config.core :refer [env]])) 13 | 14 | (defn start [] 15 | (http/start {:handler app 16 | :init init 17 | :port (:port env)})) 18 | 19 | (defn stop [] 20 | (http/stop destroy)) 21 | 22 | (defn restart [] 23 | (stop) 24 | (start)) 25 | 26 | 27 | -------------------------------------------------------------------------------- /swagger-service/src/clj/swagger_service/routes/home.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns swagger-service.routes.home 10 | (:require [swagger-service.layout :as layout] 11 | [compojure.core :refer [defroutes GET]] 12 | [ring.util.http-response :refer [ok]] 13 | [clojure.java.io :as io])) 14 | 15 | (defn home-page [] 16 | (layout/render "home.html")) 17 | 18 | (defroutes home-routes 19 | (GET "/" [] (home-page)) 20 | (GET "/docs" [] (ok (-> "docs/docs.md" io/resource slurp)))) 21 | 22 | -------------------------------------------------------------------------------- /multi-client-ws-aleph/test/clj/multi_client_ws_aleph/test/handler.clj: -------------------------------------------------------------------------------- 1 | (ns multi-client-ws-aleph.test.handler 2 | (:require 3 | [clojure.test :refer :all] 4 | [ring.mock.request :refer :all] 5 | [multi-client-ws-aleph.handler :refer :all] 6 | [multi-client-ws-aleph.middleware.formats :as formats] 7 | [muuntaja.core :as m] 8 | [mount.core :as mount])) 9 | 10 | (defn parse-json [body] 11 | (m/decode formats/instance "application/json" body)) 12 | 13 | (use-fixtures 14 | :once 15 | (fn [f] 16 | (mount/start #'multi-client-ws-aleph.config/env 17 | #'multi-client-ws-aleph.handler/app-routes) 18 | (f))) 19 | 20 | (deftest test-app 21 | (testing "main route" 22 | (let [response ((app) (request :get "/"))] 23 | (is (= 200 (:status response))))) 24 | 25 | (testing "not-found route" 26 | (let [response ((app) (request :get "/invalid"))] 27 | (is (= 404 (:status response)))))) 28 | -------------------------------------------------------------------------------- /guestbook-cljs/test/clj/guestbook/test/handler.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns guestbook.test.handler 10 | (:require [clojure.test :refer :all] 11 | [ring.mock.request :refer :all] 12 | [guestbook.handler :refer :all])) 13 | 14 | (deftest test-app 15 | (testing "main route" 16 | (let [response (app (request :get "/"))] 17 | (is (= 200 (:status response))))) 18 | 19 | (testing "not-found route" 20 | (let [response (app (request :get "/invalid"))] 21 | (is (= 404 (:status response)))))) 22 | -------------------------------------------------------------------------------- /multi-client-ws-aleph/env/dev/clj/user.clj: -------------------------------------------------------------------------------- 1 | (ns user 2 | "Userspace functions you can run by default in your local REPL." 3 | (:require 4 | [multi-client-ws-aleph.config :refer [env]] 5 | [clojure.spec.alpha :as s] 6 | [expound.alpha :as expound] 7 | [mount.core :as mount] 8 | [multi-client-ws-aleph.figwheel :refer [start-fw stop-fw cljs]] 9 | [multi-client-ws-aleph.core :refer [start-app]])) 10 | 11 | (alter-var-root #'s/*explain-out* (constantly expound/printer)) 12 | 13 | (add-tap (bound-fn* clojure.pprint/pprint)) 14 | 15 | (defn start 16 | "Starts application. 17 | You'll usually want to run this on startup." 18 | [] 19 | (mount/start-without #'multi-client-ws-aleph.core/repl-server)) 20 | 21 | (defn stop 22 | "Stops application." 23 | [] 24 | (mount/stop-except #'multi-client-ws-aleph.core/repl-server)) 25 | 26 | (defn restart 27 | "Restarts application." 28 | [] 29 | (stop) 30 | (start)) 31 | 32 | 33 | -------------------------------------------------------------------------------- /multi-client-ws-aleph/src/cljs/multi_client_ws_aleph/websockets.cljs: -------------------------------------------------------------------------------- 1 | (ns multi-client-ws.websockets 2 | (:require [cognitect.transit :as t])) 3 | 4 | (defonce ws-chan (atom nil)) 5 | (def json-reader (t/reader :json)) 6 | (def json-writer (t/writer :json)) 7 | 8 | (defn receive-transit-msg! 9 | [update-fn] 10 | (fn [msg] 11 | (update-fn 12 | (->> msg .-data (t/read json-reader))))) 13 | 14 | (defn send-transit-msg! 15 | [msg] 16 | (if @ws-chan 17 | (.send @ws-chan (t/write json-writer msg)) 18 | (throw (js/Error. "Websocket is not available!")))) 19 | 20 | (defn make-websocket! [url receive-handler] 21 | (println "attempting to connect websocket") 22 | (if-let [chan (js/WebSocket. url)] 23 | (do 24 | (set! (.-onmessage chan) (receive-transit-msg! receive-handler)) 25 | (reset! ws-chan chan) 26 | (println "Websocket connection established with: " url)) 27 | (throw (js/Error. "Websocket connection failed!")))) 28 | -------------------------------------------------------------------------------- /multi-client-ws-http-kit/test/clj/multi_client_ws_http_kit/test/handler.clj: -------------------------------------------------------------------------------- 1 | (ns multi-client-ws-http-kit.test.handler 2 | (:require 3 | [clojure.test :refer :all] 4 | [ring.mock.request :refer :all] 5 | [multi-client-ws-http-kit.handler :refer :all] 6 | [multi-client-ws-http-kit.middleware.formats :as formats] 7 | [muuntaja.core :as m] 8 | [mount.core :as mount])) 9 | 10 | (defn parse-json [body] 11 | (m/decode formats/instance "application/json" body)) 12 | 13 | (use-fixtures 14 | :once 15 | (fn [f] 16 | (mount/start #'multi-client-ws-http-kit.config/env 17 | #'multi-client-ws-http-kit.handler/app-routes) 18 | (f))) 19 | 20 | (deftest test-app 21 | (testing "main route" 22 | (let [response ((app) (request :get "/"))] 23 | (is (= 200 (:status response))))) 24 | 25 | (testing "not-found route" 26 | (let [response ((app) (request :get "/invalid"))] 27 | (is (= 404 (:status response)))))) 28 | -------------------------------------------------------------------------------- /multi-client-ws-immutant/test/clj/multi_client_ws_immutant/test/handler.clj: -------------------------------------------------------------------------------- 1 | (ns multi-client-ws-immutant.test.handler 2 | (:require 3 | [clojure.test :refer :all] 4 | [ring.mock.request :refer :all] 5 | [multi-client-ws-immutant.handler :refer :all] 6 | [multi-client-ws-immutant.middleware.formats :as formats] 7 | [muuntaja.core :as m] 8 | [mount.core :as mount])) 9 | 10 | (defn parse-json [body] 11 | (m/decode formats/instance "application/json" body)) 12 | 13 | (use-fixtures 14 | :once 15 | (fn [f] 16 | (mount/start #'multi-client-ws-immutant.config/env 17 | #'multi-client-ws-immutant.handler/app-routes) 18 | (f))) 19 | 20 | (deftest test-app 21 | (testing "main route" 22 | (let [response ((app) (request :get "/"))] 23 | (is (= 200 (:status response))))) 24 | 25 | (testing "not-found route" 26 | (let [response ((app) (request :get "/invalid"))] 27 | (is (= 404 (:status response)))))) 28 | -------------------------------------------------------------------------------- /multi-client-ws-http-kit/src/cljs/multi_client_ws_http_kit/websockets.cljs: -------------------------------------------------------------------------------- 1 | (ns multi-client-ws.websockets 2 | (:require [cognitect.transit :as t])) 3 | 4 | (defonce ws-chan (atom nil)) 5 | (def json-reader (t/reader :json)) 6 | (def json-writer (t/writer :json)) 7 | 8 | (defn receive-transit-msg! 9 | [update-fn] 10 | (fn [msg] 11 | (update-fn 12 | (->> msg .-data (t/read json-reader))))) 13 | 14 | (defn send-transit-msg! 15 | [msg] 16 | (if @ws-chan 17 | (.send @ws-chan (t/write json-writer msg)) 18 | (throw (js/Error. "Websocket is not available!")))) 19 | 20 | (defn make-websocket! [url receive-handler] 21 | (println "attempting to connect websocket") 22 | (if-let [chan (js/WebSocket. url)] 23 | (do 24 | (set! (.-onmessage chan) (receive-transit-msg! receive-handler)) 25 | (reset! ws-chan chan) 26 | (println "Websocket connection established with: " url)) 27 | (throw (js/Error. "Websocket connection failed!")))) 28 | -------------------------------------------------------------------------------- /swagger-service/test/clj/swagger_service/test/handler.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns swagger-service.test.handler 10 | (:require [clojure.test :refer :all] 11 | [ring.mock.request :refer :all] 12 | [swagger-service.handler :refer :all])) 13 | 14 | (deftest test-app 15 | (testing "main route" 16 | (let [response (app (request :get "/"))] 17 | (is (= 200 (:status response))))) 18 | 19 | (testing "not-found route" 20 | (let [response (app (request :get "/invalid"))] 21 | (is (= 404 (:status response)))))) 22 | -------------------------------------------------------------------------------- /multi-client-ws-http-kit/env/dev/clj/user.clj: -------------------------------------------------------------------------------- 1 | (ns user 2 | "Userspace functions you can run by default in your local REPL." 3 | (:require 4 | [multi-client-ws-http-kit.config :refer [env]] 5 | [clojure.spec.alpha :as s] 6 | [expound.alpha :as expound] 7 | [mount.core :as mount] 8 | [multi-client-ws-http-kit.figwheel :refer [start-fw stop-fw cljs]] 9 | [multi-client-ws-http-kit.core :refer [start-app]])) 10 | 11 | (alter-var-root #'s/*explain-out* (constantly expound/printer)) 12 | 13 | (add-tap (bound-fn* clojure.pprint/pprint)) 14 | 15 | (defn start 16 | "Starts application. 17 | You'll usually want to run this on startup." 18 | [] 19 | (mount/start-without #'multi-client-ws-http-kit.core/repl-server)) 20 | 21 | (defn stop 22 | "Stops application." 23 | [] 24 | (mount/stop-except #'multi-client-ws-http-kit.core/repl-server)) 25 | 26 | (defn restart 27 | "Restarts application." 28 | [] 29 | (stop) 30 | (start)) 31 | 32 | 33 | -------------------------------------------------------------------------------- /multi-client-ws-immutant/env/dev/clj/user.clj: -------------------------------------------------------------------------------- 1 | (ns user 2 | "Userspace functions you can run by default in your local REPL." 3 | (:require 4 | [multi-client-ws-immutant.config :refer [env]] 5 | [clojure.spec.alpha :as s] 6 | [expound.alpha :as expound] 7 | [mount.core :as mount] 8 | [multi-client-ws-immutant.figwheel :refer [start-fw stop-fw cljs]] 9 | [multi-client-ws-immutant.core :refer [start-app]])) 10 | 11 | (alter-var-root #'s/*explain-out* (constantly expound/printer)) 12 | 13 | (add-tap (bound-fn* clojure.pprint/pprint)) 14 | 15 | (defn start 16 | "Starts application. 17 | You'll usually want to run this on startup." 18 | [] 19 | (mount/start-without #'multi-client-ws-immutant.core/repl-server)) 20 | 21 | (defn stop 22 | "Stops application." 23 | [] 24 | (mount/stop-except #'multi-client-ws-immutant.core/repl-server)) 25 | 26 | (defn restart 27 | "Restarts application." 28 | [] 29 | (stop) 30 | (start)) 31 | 32 | 33 | -------------------------------------------------------------------------------- /multi-client-ws-immutant/src/cljs/multi_client_ws_immutant/websockets.cljs: -------------------------------------------------------------------------------- 1 | (ns multi-client-ws.websockets 2 | (:require [cognitect.transit :as t])) 3 | 4 | (defonce ws-chan (atom nil)) 5 | (def json-reader (t/reader :json)) 6 | (def json-writer (t/writer :json)) 7 | 8 | (defn receive-transit-msg! 9 | [update-fn] 10 | (fn [msg] 11 | (update-fn 12 | (->> msg .-data (t/read json-reader))))) 13 | 14 | (defn send-transit-msg! 15 | [msg] 16 | (if @ws-chan 17 | (.send @ws-chan (t/write json-writer msg)) 18 | (throw (js/Error. "Websocket is not available!")))) 19 | 20 | (defn make-websocket! [url receive-handler] 21 | (println "attempting to connect websocket") 22 | (if-let [chan (js/WebSocket. url)] 23 | (do 24 | (set! (.-onmessage chan) (receive-transit-msg! receive-handler)) 25 | (reset! ws-chan chan) 26 | (println "Websocket connection established with: " url)) 27 | (throw (js/Error. "Websocket connection failed!")))) 28 | 29 | -------------------------------------------------------------------------------- /reporting-example/test/clj/reporting_example/test/handler.clj: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns reporting-example.test.handler 10 | (:require [clojure.test :refer :all] 11 | [ring.mock.request :refer :all] 12 | [reporting-example.handler :refer :all])) 13 | 14 | (deftest test-app 15 | (testing "main route" 16 | (let [response (app (request :get "/"))] 17 | (is (= 200 (:status response))))) 18 | 19 | (testing "not-found route" 20 | (let [response (app (request :get "/invalid"))] 21 | (is (= 404 (:status response)))))) 22 | -------------------------------------------------------------------------------- /swagger-service/src/cljs/swagger_service/ajax.cljs: -------------------------------------------------------------------------------- 1 | ;--- 2 | ; Excerpted from "Web Development with Clojure, Second Edition", 3 | ; published by The Pragmatic Bookshelf. 4 | ; Copyrights apply to this code. It may not be used to create training material, 5 | ; courses, books, articles, and the like. Contact us if you are in doubt. 6 | ; We make no guarantees that this code is fit for any purpose. 7 | ; Visit http://www.pragmaticprogrammer.com/titles/dswdcloj2 for more book information. 8 | ;--- 9 | (ns swagger-service.ajax 10 | (:require [ajax.core :as ajax])) 11 | 12 | (defn default-headers [request] 13 | (update 14 | request 15 | :headers 16 | #(merge 17 | {"Accept" "application/transit+json" 18 | "x-csrf-token" js/csrfToken} 19 | %))) 20 | 21 | (defn load-interceptors! [] 22 | (swap! ajax/default-interceptors 23 | conj 24 | (ajax/to-interceptor {:name "default headers" 25 | :request default-headers}))) 26 | 27 | 28 | -------------------------------------------------------------------------------- /guestbook-datomic/src/clj/guestbook_datomic/handler.clj: -------------------------------------------------------------------------------- 1 | (ns guestbook-datomic.handler 2 | (:require 3 | [guestbook-datomic.layout :refer [error-page]] 4 | [guestbook-datomic.routes.home :refer [home-routes]] 5 | [compojure.core :refer [routes wrap-routes]] 6 | [compojure.route :as route] 7 | [guestbook-datomic.env :refer [defaults]] 8 | [mount.core :as mount] 9 | [guestbook-datomic.middleware :as middleware])) 10 | 11 | (mount/defstate init-app 12 | :start ((or (:init defaults) identity)) 13 | :stop ((or (:stop defaults) identity))) 14 | 15 | (mount/defstate app 16 | :start 17 | (middleware/wrap-base 18 | (routes 19 | (-> #'home-routes 20 | (wrap-routes middleware/wrap-csrf) 21 | (wrap-routes middleware/wrap-formats)) 22 | (route/not-found 23 | (:body 24 | (error-page {:status 404 25 | :title "page not found"})))))) 26 | 27 | -------------------------------------------------------------------------------- /file-upload-progress/src/clj/file_upload_progress/handler.clj: -------------------------------------------------------------------------------- 1 | (ns file-upload-progress.handler 2 | (:require [compojure.core :refer [routes wrap-routes]] 3 | [file-upload-progress.layout :refer [error-page]] 4 | [file-upload-progress.routes.home :refer [home-routes]] 5 | [compojure.route :as route] 6 | [file-upload-progress.env :refer [defaults]] 7 | [mount.core :as mount] 8 | [file-upload-progress.middleware :as middleware])) 9 | 10 | (mount/defstate init-app 11 | :start ((or (:init defaults) identity)) 12 | :stop ((or (:stop defaults) identity))) 13 | 14 | (def app-routes 15 | (routes 16 | (-> #'home-routes 17 | (wrap-routes middleware/wrap-csrf) 18 | (wrap-routes middleware/wrap-formats)) 19 | (route/not-found 20 | (:body 21 | (error-page {:status 404 22 | :title "page not found"}))))) 23 | 24 | 25 | (defn app [] (middleware/wrap-base #'app-routes)) 26 | -------------------------------------------------------------------------------- /file-upload-progress/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block content %} 3 | 4 |upload progress
19 |If you're seeing this message, that means you haven't yet compiled your ClojureScript!
15 |Please run lein figwheel to start the ClojureScript compiler and reload the page.
See ClojureScript documentation for further details.
25 |If you're seeing this message, that means you haven't yet compiled your ClojureScript!
21 |Please run lein figwheel to start the ClojureScript compiler and reload the page.
See ClojureScript documentation for further details.
23 |