From f20a09da3d09f54842254706b0cf2e3d05a82ca1 Mon Sep 17 00:00:00 2001 From: s-ol Date: Fri, 15 Mar 2019 00:40:35 +0100 Subject: initial commit --- src/redirectly/core.clj | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/redirectly/core.clj (limited to 'src') diff --git a/src/redirectly/core.clj b/src/redirectly/core.clj new file mode 100644 index 0000000..8b7025f --- /dev/null +++ b/src/redirectly/core.clj @@ -0,0 +1,32 @@ +(ns redirectly.core + (:require [carica.core :refer [config clear-config-cache!]] + [ring.util.response :as response])) + +(def routes (config :routes)) + +(defn matches? [[slug route] uri] + (when (= uri (str "/" (name slug))) + route)) + +(defn status [route] + (or (:status route) 307)) + +(defn url [route] + (:to route)) + +(defmulti url (fn [{to :to}] + (if (vector? to) + (first to) + :url))) + +(defmethod url :url [{to :to}] to) +(defmethod url :mmm [{[_ path] :to}] (str "//mmm.s-ol.nu" path)) + +(defn handler [req] + (if-let [route (some #(matches? % (:uri req)) routes)] + (response/redirect (url route) (status route)) + (-> (response/not-found (config :404)) + (response/content-type "text/html")))) + +(defn destroy [] + (clear-config-cache!)) -- cgit v1.2.3