Serve 404 page when none route matches

next
Marcin Kulik 8 years ago
parent 1e08b39e49
commit 4fe17fbc82

@ -7,7 +7,7 @@
[user-database :as udb]]
[asciinema.model.asciicast :as asciicast]
[asciinema.util.io :refer [with-tmp-dir]]
[asciinema.yada :refer [resource]]
[asciinema.yada :refer [resource not-found-model]]
[clj-time.core :as t]
[clojure.java
[io :as io]
@ -103,4 +103,4 @@
(defn asciicasts-endpoint [{:keys [db file-store exp-set executor]}]
["" [["/a/" [[[:token ".json"] (asciicast-json-resource db file-store)]
[[:token ".png"] (asciicast-png-resource db file-store exp-set executor)]]]
[true (yada/as-resource nil)]]])
[true (yada/resource not-found-model)]]])

@ -2,14 +2,18 @@
(:require [clojure.java.io :as io]
[yada.yada :as yada]))
(defn not-found-response [ctx]
(case (yada/content-type ctx)
"text/html" (io/input-stream (io/resource "asciinema/errors/404.html"))
"Not found"))
(def not-found-model
{:produces
#{"text/html" "text/plain"}
:response
(fn [ctx]
(assoc (:response ctx)
:status 404
:body (case (yada/content-type ctx)
"text/html" (io/input-stream (io/resource "asciinema/errors/404.html"))
"Not found")))})
(defn resource [model]
(-> model
(update-in [:responses 404] #(or %
{:produces #{"text/html" "text/plain"}
:response not-found-response}))
(update-in [:responses 404] #(or % not-found-model))
yada/resource))

Loading…
Cancel
Save