small medium large xlarge

16 Dec 2013, 21:55
Konrad (2 posts)

Hi I’m trying to run the liberator-service application. The home.html is not loading and http://localhost:3000/ displays “Resource not found.”.

I’ve added println statement to :exists?

    (fn [context]
      (let [f (file (str (io/resource-path) "/home.html"))]
        (println (str (io/resource-path) "/home.html"))
        [(.exists f) {::file f}]))

the result is: /C:/Workspace/Clojure/web-devith-clojure/liberator-service/resources/public%5c/home.html

it looks like “%5c” which in URL encode is \ is added to my path. Anyone has any idea why?

15 Dec 2013, 20:49
Dmitri Sotnikov (112 posts)

I saw this problem from a few other Windows users. The (io/resource-path) returns a, and it looks like on Windows toString call on the URL will produce a malformed path.

Could you try calling getFile on the resulting URL to see if that helps?

(-> ( ".") (.getFile) (str "/home.html"))
16 Dec 2013, 21:51
Konrad (2 posts)

Thanks Dmitri, you set me in the right direction. I finally got the code working.

My first problem was that I had the following project structure: liberator-service\resources\public\home.html

Accessing just resource folder couldn’t find home.html file. I had to go public/home.html

This is my copy that works:

(defresource home
    :available-media-types ["text/html"]

    (fn [context]
      (let [f (file (-> ( "public/home.html")))]

        ; sanity-check: print the resource path:
        (println (str 
                   ( home.html" )))

        ; sanity-check: does the file exist?
        (println (.exists f))

        [(.exists f) {::file f}]))

    (fn [{{{resource :resource} :route-params} :request}]
      (file  (-> ( "public/home.html") )))

    (fn [{{{resource :resource} :route-params} :request}]
      (.lastModified (file (-> ( "public/home.html") )))))
16 Dec 2013, 23:08
Dmitri Sotnikov (112 posts)

Ah good to hear that worked, by the way you don’t need the -> if you only have a single operation like ( "public/home.html"). The -> macro lets you chain expressions so you could write:

(-> ( "public/home.html") file)

this passes the output of io/resource to file and it’s same as writing:

(file ( "public/home.html"))
22 Feb 2014, 09:24
Robert Dober (20 posts)

output? That hurts for a functional language ;)

Let us say result, agreed?

01 Mar 2014, 14:10
Dmitri Sotnikov (112 posts)

result would be more proper :)

You must be logged in to comment