Skip to content

Instantly share code, notes, and snippets.

@kmtr
Last active December 17, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmtr/5523132 to your computer and use it in GitHub Desktop.
Save kmtr/5523132 to your computer and use it in GitHub Desktop.
ring directoryindex middleware / -> /index.html /foo/ -> /foo/index.html /foo -> /foo
; clojure "1.5.1"
; compojure "1.1.5"
(ns app.handler
(:use compojure.core)
(:require [compojure.handler :as handler]
[compojure.route :as route]))
; middleware
(defn directoryindex [handler index]
(fn [request]
(let [uri (re-find #"^.*/$" (request :uri))]
(handler
(if uri
(assoc request :uri (str uri index))
request)))))
(defroutes app-routes
(GET "/" [] "Hello World")
(route/resources "/")
(route/not-found "Not Found"))
(def app
(-> (handler/site app-routes)
(directoryindex "index.html")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment