Skip to content

Instantly share code, notes, and snippets.

@mtnygard
Created November 23, 2016 13:17
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 mtnygard/9f77639865592608ed3aa87a42191468 to your computer and use it in GitHub Desktop.
Save mtnygard/9f77639865592608ed3aa87a42191468 to your computer and use it in GitHub Desktop.
Using the not-found-interceptor as a catchall
(ns support.service
(:require [io.pedestal.http :as http]
[io.pedestal.http.route :as route]))
(defn about-page
[request]
{:status 200 :body (format "Clojure %s - served from %s"
(clojure-version)
(route/url-for ::about-page))})
(def home-page
{:name ::home-page
:enter (fn [context]
(assoc context :response {:status 200 :body "Hello world!"}))})
(def redirect-home
{:name ::redirect-home
:enter (fn [context]
(assoc context :response {:status 302 :body "Go home" :headers {"Location" "/"}}))})
(defn routes
[]
(route/expand-routes
`[[["/" {:get home-page}
["/api" {:post about-page
:get redirect-home}]]]]))
(def service {:env :prod
::http/routes routes
::http/not-found-interceptor redirect-home
::http/resource-path "/public"
::http/type :jetty
::http/port 8081})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment