Skip to content

Instantly share code, notes, and snippets.

@metaforte
Created September 16, 2018 20:32
Show Gist options
  • Save metaforte/6ed1906754750450a636b0e44f09a513 to your computer and use it in GitHub Desktop.
Save metaforte/6ed1906754750450a636b0e44f09a513 to your computer and use it in GitHub Desktop.
Modern ClojureScript

Chpater 2: Browser Repl

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

Chpater 3: Ring and Compojure

Ring is the http server wrapper. Comjure is the routing library

  1. 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 }
  1. 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))
  1. 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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment