Using the not-found-interceptor as a catchall
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 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