Broken links when deploying Clojure webapps to Jetty with relative links and non-root context path -


i've been experimenting writing webapps in clojure, , it's been pretty easy until now. followed chas emerick's excellent screencast starting clojure , got url shortener , running pretty quickly. next wanted able deploy it, , that's when trouble started.

when run in development or deploy jetty root webapp, fine, when deploy context path, doesn't. or, rather, works. compojure routes still work, form action links in html files broken , give me 404's.

this compojure route setup:

  (defroutes app*     (rt/resources "/")     (get "/" request (homepage request))     (post "/shorten" request           (let [id (shorten (-> request :params :url))]             (response/redirect "/")))     (get "/:id" [id] (redirect id)))    (def app (compojure.handler/site app*)) 

and here html homepage template:

<!doctype html> <html> <head>     <title>insert title here</title>     <link type="text/css" rel="stylesheet" href="site.css" /> </head> <body>     <form method="post" action="shorten">         <input type="text" name="url" />         <input type="submit" value="shorten!" />     </form> </body> </html> 

the problem action="shorten"url. when deployed jetty context path of /example work fine, until trigger form submit. jetty complains can't find localhost:8080/shorten means (i think) it's not being treated relative path, absolute one.

so, question is: how fix this? guess specify full path in action link, inflexible , make harder run servlet in development. there way configure way out of this? or magic url prefix (like ~/ in razor) right thing?

i had same problem. change line:

(post "/shorten" request 

to

(post "shorten" request 

and should work (well, did me)


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -