Skip to content

Commit

Permalink
implement trailing slash redirect via pedestal
Browse files Browse the repository at this point in the history
Workaround for traefik/traefik#4247
Usually Traefik and other reverse proxies handle this.
  • Loading branch information
martinklepsch committed Nov 28, 2018
1 parent 6978cb3 commit 81370c9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/cljdoc/server/pedestal.clj
Expand Up @@ -249,6 +249,15 @@
(fn [request opts]
(etag/add-file-etag request false)))})

(def redirect-trailing-slash-interceptor
{:name ::redirect-trailing-slash
:leave (fn [ctx]
(let [uri (-> ctx :request :uri)]
(cond-> ctx
(.endsWith uri "/")
(assoc :response {:status 301
:headers {"Location" (subs uri 0 (dec (.length uri)))}}))))})

(def not-found-interceptor
{:name ::not-found-interceptor
:leave (fn [context]
Expand Down Expand Up @@ -346,7 +355,10 @@
::http/resource-path "public"
::http/not-found-interceptor not-found-interceptor}
http/default-interceptors
(update ::http/interceptors #(into [sentry/interceptor etag-interceptor] %))
(update ::http/interceptors #(into [sentry/interceptor
etag-interceptor
redirect-trailing-slash-interceptor]
%))
(http/create-server)
(http/start)))

Expand Down

0 comments on commit 81370c9

Please sign in to comment.