Created
July 21, 2014 17:37
-
-
Save shaunr0b/624f1d5c5400956af23d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hello-world.core | |
(:require [org.httpkit.server :refer [run-server]] | |
[compojure.core :refer (GET defroutes)] | |
[compojure.route :as route] | |
[hiccup.core :refer (html)] | |
[hiccup.page :refer (html5)] | |
[ring.middleware.resource :refer (wrap-resource)] | |
[ring.middleware.file-info :refer (wrap-file-info)])) | |
(defn make-list [collection] | |
[:ul | |
(map | |
#(identity [:li %]) | |
collection)]) | |
(defn home-page | |
[request] | |
(str request)) | |
#_(html5 [:head [:title "My Page"] | |
[:style {:type "text/css"} | |
"body { background-color: #fff; color: #000; }"]] | |
[:body | |
[:h1 "Big Hello World"] | |
(make-list (:names request)) | |
[:img {:src "images/littlefinger.gif"}] | |
]) | |
;; <h1 style='background-color: blue;"> Contents </h1> | |
(defroutes our-routes | |
(GET "/" [] home-page)) | |
;; (fn fn1 [request] | |
;; (trim-response | |
;; (fn fn2 [request] | |
;; (if url "/my-app/some.html" "hello world")))) | |
(defn wrap-names [handler names] | |
(fn [request] | |
(let [request (assoc request :names names) | |
response (handler request)] | |
(println request) | |
(println response)))) | |
(def app | |
(-> our-routes | |
(wrap-names ["Shaun" "Tyler" "Emily" "Aaron"]) | |
(wrap-resource "public") | |
(wrap-file-info))) | |
(def server (atom nil)) | |
(defn stop [] | |
(when @server | |
(@server)) | |
(reset! server nil)) | |
(defn start [] | |
(stop) | |
(reset! server (run-server app {:port 8080}))) | |
(start) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment