Tomcat Deployment Context

24 views
Skip to first unread message

Jonathan Blaisure

unread,
Jul 1, 2019, 8:58:05 AM7/1/19
to Luminus
Hello, 
I am working on a project using the luminus template with shadow-cljs, war, kee-frame, and swagger options through the luminus template. 

I am able to deploy to tomcat as ROOT.war and everything just works. 

When I deploy to any other context the routes do not seem to pick up the context. Does anyone have any tips on how to accomplish this? I would greatly appreciate it!

I have also tried using the +servlet option with no luck. 

Thanks!

Dmitri

unread,
Jul 1, 2019, 10:18:07 AM7/1/19
to Luminus
The problem is that the servlet context is not part of the HTTP protocol, and the client isn't aware of it. So, you have to manually track this prefix in your application. To do that, you'd need to add a piece of middleware that injects the servlet context in the request, e.g:

(defn wrap-context [handler]
    (fn [request]
      (handler
        (assoc request
          :servlet-context
          (when-let [context (:servlet-context request)]
            ;; If we're not inside a servlet environment
            ;; (for example when using mock requests), then
            ;; .getContextPath might not exist
            (try (.getContextPath ^ServletContext context)
                 (catch IllegalArgumentException _ context)))))))



Then in the layout namespace, you'd want to read the
:servlet-context key, and inject it in the page. The requests from the page have to prefix this context to the URL.

Jonathan Blaisure

unread,
Jul 1, 2019, 11:29:33 AM7/1/19
to Luminus
Thanks Dmitri for your quick response. 

I am still missing something b/c when I add this middleware and inject into selmer that page doesn't load in tomcat at all. I have tried adding the context "testwar" to the reitit routes as well. 

Is there something else I need to modify for it to work?

Thanks!

Dmitri

unread,
Jul 2, 2019, 10:37:44 AM7/2/19
to Luminus
I haven't actually done much with app servers in a while myself, so not entirely sure what the issue there is. It sounds like you might have to do a bit of tracing to see what's happening. If the page fails to load entirely, it sounds like the middleware might not be throwing an error. First thing I'd check is whether you're able to log the context inside the middleware function, and that it matches what's expected.
Reply all
Reply to author
Forward
0 new messages