connect.cljs
(ns modern-cljs.connect
(:require [clojure.browser.repl :as repl]))
(repl/connect "http://localhost:9000/repl")
lein do clean, cljsbuild once
lein trampoline cljsbuild repl-listen
:cljs/quit to quit repl
Ring is the http server wrapper. Comjure is the routing library
- Add ring, compojure, and lein-ring plugin to the project
:dependencies [
[javax.servlet/servlet-api "2.5"]
[ring "1.7.0"]
[compojure "1.4.0"]]
:plugins [ [lein-ring "0.9.7"]]
:ring {:handler modern-cljs.core/handler }
- Add handler to core.clj
(ns modern-cljs.core
(:require [compojure.core :refer :all]
[compojure.handler :as handler]
[compojure.route :as route]))
(defroutes app-routes
; to serve document root address
(GET "/" [] "<p>Hello from compojure</p>")
; to serve static pages saved in resources/public directory
(route/resources "/")
; if page is not found
(route/not-found "Page not found"))
;; site function creates a handler suitable for a standard website,
;; adding a bunch of standard ring middleware to app-route:
(def handler
(handler/site app-routes))
- Run the server, browser repl and access browser repl from Browser
lein ring server
lein do clean, cljsbuild once
lein trampoline cljsbuild repl-listen
Chapter 4: