leontalbot
leontalbot

Reputation: 2543

How do I make a page visible with or without ending slash in the url?

I use noir.

Having :

(defpage "/welcome" [] "Welcome to Noir!")

I do I make both these URL works:

http://localhost:8080/welcome 
http://localhost:8080/welcome/

Thanks!

EDIT: Here's the complete answer.

In server.clj, add up (:use [ring.util.response :only [redirect]])

Then write :

(defn wrap-slash 
  ""
  [handler]
  (fn [{:keys [uri] :as req}]
    (if (and (.endsWith uri "/") (not= uri "/"))
      (handler (assoc req :uri (.substring uri
                                0 (dec (count uri)))))
      (handler req))))

(server/add-middleware wrap-slash)

Upvotes: 0

Views: 87

Answers (1)

Jared314
Jared314

Reputation: 5231

Noir's routing is more strict than some others, so take a look at this question which, while having a different title, is asking the same thing.

Upvotes: 1

Related Questions