2
votes

I am making a web-app using Clojure/ring/compojure and am having trouble with the routing. I have two files: web.clj and landing.clj. I want to route the user who navigates to the uri from the web.clj handler to the landing.clj one and for the home function to be called which will render the front page of my app. I can't for the life of me seem to grok the semantics, please help. Documentation that I read assumes a lot of web-dev knowledge and I am a beginner. I am now getting a 404 error message in the browser when I run the local server from Leiningen. I know That it is going through the defroutes in the landing.clj file, because the address bar shows http://0.0.0.0:5000/landing, when I load http://0.0.0.0:5000.

This is the code for my web.clj file, which successfully redirects to the landing.clj file:

  (defroutes app
  (ANY "/repl" {:as req}
       (drawbridge req))
  (GET "/" [] (redirect "landing")) ;; come fix this later
  (ANY "*" []
       (route/not-found (slurp (io/resource "404.html")))))

This is from the landing.clj file, the error is located somewhere with the GET "/" function:

(defroutes app
  (GET "/" []
       {:status 200
        :headers {"Content-Type" "text/html"}
        :body (home)})
  (POST "/" [weights grades] ((process-grades (read-string weights) (read-string grades)) ))
  (ANY "*" []
       (route/not-found (slurp (io/resource "404.html")))))
1

1 Answers

2
votes

The below expression seems to have extra parenthesis:

(POST "/" [weights grades] ((process-grades (read-string weights) (read-string grades)) ))

It should be:

(POST "/" [weights grades] (process-grades (read-string weights) (read-string grades)) )