Skip to content

Instantly share code, notes, and snippets.

@swannodette
Forked from devn/web.clj
Created April 1, 2010 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save swannodette/351783 to your computer and use it in GitHub Desktop.
Save swannodette/351783 to your computer and use it in GitHub Desktop.
(ns defn-test
(:use clj-html.core
[net.cgrand.moustache :only [app]]
[ring.adapter.jetty :only [run-jetty]]
[ring.util.response :only [response]]))
(defhtml application [text body]
[:html
[:head
[:title text]]
[:body
[:h3 text]
body]])
(defhtml code-list [body]
[:ul body])
(defhtml code-block [[code result]]
[:li [:pre code] [:pre ";; =&gt" result]])
(defn test-fn*
[#^String text]
(response
(application text
(code-list (code-block text)))))
(def test-web
(app
["examples" [text #".*"]] {:get (fn [req] (test-fn* text))}
[#".*"] {:get ["all routes!"]}))
(defonce server (run-jetty #'test-web {:port 8080 :join? false}))
@devn
Copy link

devn commented Apr 1, 2010

(declare test-web)
(def server (doto (Thread. #(run-jetty #'test-web {:port 8080})) .start))

@cgrand
Copy link

cgrand commented Apr 1, 2010

["examples" [text #".*"]] matches /examples/anything but not /examples/anything/ nor /examples/anything/else... However the #".*" is redundant, just write ["examples" text].

[#".*"] is likewise equivalent to [_] but only matches /something. If you want to match all urls you have to use [&].

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