Previously I have discussed on how to run a ring app using boot. Here we will see how to run a ring app that uses compojure for routes using boot. We will be using jetty as the server. The difference is that in a pure ring based app, you will pass the ring handler function to the run-jetty
method, but here you will pass (compojure.handler/site routes-method)
to run-jetty
method.
compojure-boot
├── build.boot
└── src
└── net
└── jsloop
└── server
└── core.clj
;core.clj
(ns net.jsloop.server.core
(:use compojure.core)
(:require [ring.adapter.jetty :as jetty]
[compojure.handler :as handler]))
(defn greet []
"Hello from compojure")
(defroutes api-routes
(GET "/" [] (greet)))
(defn run-server []
(jetty/run-jetty (handler/site api-routes) {:port 8080}))
;boot.clj
(set-env!
:source-paths #{"src"}
:dependencies '[[org.clojure/clojure "1.8.0"]
[ring "1.5.0"]
[compojure "1.5.1"]])
(require '[net.jsloop.server.core :as server])
(deftask run []
(with-pre-wrap fileset (server/run-server) fileset))
From the project root, run the server using boot as
boot run
Open http://localhost:8080 to see the response.