Servlet context path and ring/moustache

253 views
Skip to first unread message

Allen Johnson

unread,
Apr 12, 2011, 11:51:16 AM4/12/11
to clojure...@googlegroups.com
Hello everyone,

I'm using moustache and ring in a project. Also, I'm using lein-ring
so I can easily deploy as a war file. Java servlet containers allow
you to deploy a web app to different context paths. Say during
development, on my local machine, I'd like the context path to be "/"
but when deployed to production I'd like it to be "/myapp".

Is there a way to accomplish this with the libraries listed above?
ATM, my moustache routes do not match unless I'm using the root path.

Thanks,
Allen

James Reeves

unread,
Apr 12, 2011, 2:11:42 PM4/12/11
to clojure...@googlegroups.com
On 12 April 2011 16:51, Allen Johnson <akjoh...@gmail.com> wrote:
> I'm using moustache and ring in a project. Also, I'm using lein-ring
> so I can easily deploy as a war file. Java servlet containers allow
> you to deploy a web app to different context paths. Say during
> development, on my local machine, I'd like the context path to be "/"
> but when deployed to production I'd like it to be "/myapp".

lein-ring adds two additional keys when compiled as a war:

:path-info - equivalent to getPathInfo
:context - equivalent to getContextPath

This stems from a discussion we had on the Ring group. It was
suggested that these keys be added to the Ring SPEC, but Mark wanted
to see how they worked in practise first.

These keys are supported by the stuff I've written (Compojure,
lein-ring, etc.), but I don't believe Moustache supports them.
However, you could cobble together some middleware that rewrites the
:uri key with the :path-info key:

(defn wrap-context-uri [handler]
(fn [request]
(handler (assoc request uri (request :path-info)))))

- James

Reply all
Reply to author
Forward
0 new messages