On Mon, Dec 24, 2012 at 9:27 AM, James Reeves <
ja...@booleanknot.com> wrote:
> On 24 December 2012 11:30, Sean Bowman <
pic...@gmail.com> wrote:
>>
>> > Also, I'm just curious for my own edification why `update-in` works in
>> > one environment and not the other.
>>
>> I'm like you: I'd like to know the answer to that as well, and if I were
>> in your shoes, it would be driving me nuts as well. I'm not sure why you're
>> seeing something different inside a J2EE container than from without.
>> Unfortunately I stopped deploying into containers with our Compojure apps
>> and just run them with Jetty or Aleph (Netty) embedded directly in the app
>> (I found it makes deployments easier), so I haven't fought this battle
>> you're fighting right now.
>
>
> It's likely because when he deploys it to Tomcat or Jetty, the path of the
> application changes to a subdirectory.
No, that's not it. The path is always "/".
I was too quick with my "it works" proclamation. Sort of.
This works in Ring but not Jetty or Tomcat.
(defn- wrap-dir-index [handler]
(fn [req]
(handler
(update-in req (filter #(contains? req %) [:path-info :uri])
#(if (re-find #"/$" %) (format "%sindex.html" %) %)))))
When I remove `:uri` in the sequence above it does work in Jetty or
Tomcat. I can reduce this further such that just this:
(defn- wrap-dir-index [handler]
(fn [req]
(do
(update-in req [:path-info :uri] str)
(handler req))))
doesn't work in Jetty or Tomcat. The error is a little bit more
constructive in this case. For example:
java.lang.ClassCastException: java.lang.String cannot be cast to
clojure.lang.Associative
at clojure.lang.RT.assoc(RT.java:691)
at clojure.core$assoc.invoke(core.clj:187)
at clojure.core$update_in.doInvoke(core.clj:5472)
at clojure.lang.RestFn.invoke(RestFn.java:445)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invoke(core.clj:607)
at clojure.core$update_in.doInvoke(core.clj:5471)
at clojure.lang.RestFn.invoke(RestFn.java:445)
at mametipsum.middleware$wrap_dir_index$fn__74.invoke(middleware.clj:10)
If I look at the type of (:uri req) it is java.lang.String.
The plot thickens...
Thanks.
-Tom
>
> For instance, in development you might access your application at
>
http://localhost:3000, but when you deploy it to a servlet container as a
> war file, the path might be
http://localhost:8080/testapp.
>
> It's important to realise that the :uri key contains the URI of the request,
> not the relative path. So if :uri is "/" in development, when you deploy it
> to a servlet container, that same :uri key might be "/testapp" instead.
>
> So what do you use instead? Well, this (or (:path-info request) (:uri
> request)) should cover all bases. When deployed under a context macro, or as
> a war file, the :path-info key is set, so if you check that first for the
> relative path, and then fall back on the war if that's not found, that
> should work.
>
> You should also avoid changing the :uri key - update the :path-info key
> instead if you want to change the relative path in some way.
>
> - James
>
> --
> You received this message because you are subscribed to the Google Groups
> "Compojure" group.