Hi!
TL;DR shadow.cljs app.js
served by Ring in Cloujre app deployed in Tomcat via lein uberwar
, how to generate context-relative links (so relative URLs in HTML/JS will be relative to http://127.0.0.1:8080/myap-0.1.0-SNAPSHOT-standalone/
instead of http://127.0.0.1:8080/
I am currently working on mixed lein
+ shadow-cljs
app (lein
for backend, shadow-cjls
for frontend). During development, I start backend with lein
and ring
and start frontend with shadow-cljs
pointing at backend URL (http://127.0.0.1:3000/api
, let’s say).
On „production” situation looks a bit different. I don’t need and don’t want separate backend and frontend so I first do shadow-cljs release app
, that creates app.js
file inresources/public/js
and my Ring server hosts:
(defroutes app
(...)
(ANY "/api/config/commit" [] config-commit)
(GET "/" [] (ring-response/redirect "index.html"))
(route/resources "/")
(route/not-found "Page not found"))
After that, lein uberwar
produces nice WAR for backend with integrated frontend, ready for Tomcat deployment. Awesome!
But I’ve quickly ran into issues. In general, the problem is that all my URLs in my fronted are relative, like:
[:> bs/NavItem {:event-key 1 :href "/status"} [bold-if-active :status "Status"]]
Unfortunately, after deployment in Tomcat my app becomes available under URL like:
http://127.0.0.1:8080/myap-0.1.0-SNAPSHOT-standalone/index.html
- and my Status URL takes me to the http://127.0.0.1:8080/status
which is obviously invalid.
Here are some clues how to do this in JSP: https://stackoverflow.com/questions/6615641/how-do-you-get-the-contextpath-from-javascript-the-right-way - but it all seems very JSP-specific and I have no clue how to apply this to my ClojureScript problem.
Am I doing something extremely unsupported (this lein + shadow mix)? Or am I missing something? It’s obvious that it should not work the way I’ve done it, but how to do it then?
Thanks!
Slawek