luminus-framework / luminus-template

a template project for the Luminus framework
http://www.luminusweb.net/
MIT License
648 stars 147 forks source link

Luminus template +cljs produces bug in routes.home namespace #522

Open cindywu opened 3 years ago

cindywu commented 3 years ago

Creating a new luminus project using lein new luminus new-project +cljs produces a bug in the new-project.routes.home namespace.

When the user runs lein run they will get this error:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at clojure.main.<clinit>(main.java:20)
Caused by: java.lang.RuntimeException: Unable to resolve symbol: ok in this context, compiling:(new_proj/routes/home.clj:12:19)

To resolve the error, go into new-project.routes.home and make the following change:

(defroutes home-routes
  (GET "/" [] (home-page))
  (GET "/docs" [] (ok (-> "docs/docs.md" io/resource slurp))))

Change ok to response/ok.

I am pretty new to Clojure(Script), but if someone points me in the right direction I can try and fix and submit a PR.

yogthos commented 3 years ago

It looks like you might have an older version of the template. Might be worth checking if you have a specific version pinned in your ~/.lein/profiles.clj, and you could clear the local maven cache for the template by removing the ~/.m2/repository/luminus/lein-template/ folder.

The latest version of the template should be generating the following content for new-project.routes.home:

(ns new-project.routes.home
  (:require
   [new-project.layout :as layout]
   [clojure.java.io :as io]
   [new-project.middleware :as middleware]
   [ring.util.response]
   [ring.util.http-response :as response]))

(defn home-page [request]
  (layout/render request "home.html"))

(defn home-routes []
  [""
   {:middleware [middleware/wrap-csrf
                 middleware/wrap-formats]}
   ["/" {:get home-page}]
   ["/docs" {:get (fn [_]
                    (-> (response/ok (-> "docs/docs.md" io/resource slurp))
                        (response/header "Content-Type" "text/plain; charset=utf-8")))}]])