0

I've created a project using Luminus with the following command:

lein new luminus myapp +mysql +kee-frame +swagger +oauth +kibit

In this project I created an API call that calls a function to read a file from disk. The API Call (partly):

{:get {:summary "Returns a file from disk to show in GUI"
       :responses {200 {:body ::val/my-file}}
       :handler (constantly
                  {:status 200
                   :body (gui/get-file)})}}

The function get-file is in the namespace myapp.db.gui-related and looks like this:

(defn get-file
  []
  (log/info "Trying to retrieve file")
  (read-string (slurp "file.edn")))

When I start a REPL and enter the command (mount/start) the application starts normally and I can make the API call to see the content of the file. The file location is now in the root of my project. However, if I place the file in resources/myapp and change the slurp command to either (slurp "myapp/file.edn") or (slurp "resources/myapp/file.edn"), I get an error after running (mount/start) and the application is not started. I get the same error if I try to read a file with an absolute path like (slurp "C:\\Development\\file.edn")

2020-04-30 12:02:03,512 [nREPL-session-88d31cf8-b119-4a87-901d-3eee1eb61cc7] INFO  myapp.env --=[myapp started successfully using the development profile]=-
2020-04-30 12:02:03,607 [nREPL-session-88d31cf8-b119-4a87-901d-3eee1eb61cc7] INFO  myapp.db.gui-related - Trying to retrieve file    
Execution error (ConnectException) at java.net.DualStackPlainSocketImpl/connect0 (DualStackPlainSocketImpl.java:-2).
    Connection refused: connect

In this project I'll have a lot of 'config' files to read and I would like to be able to place them in one or more sub folders in the root of my project. Besides this there will be another file to be read in, which will be outside the folder structure of my application.

How can I read these files?

2 Answers2

0

With java you should always use forward slashes; that is (slurp "C:/Development/file.edn"), I think (I don't have windows).

Also reading from relative path should work; you can check the current working dir for your REPL with (System/getProperty "user.dir") and verify that the path is correct.

Juraj Martinka
  • 3,991
  • 2
  • 23
  • 25
0

Sorry. Error had nothing to do with the slurp function. In another function I still had a URL for an API call hard coded and this had changed. Therefore I got this

Execution error (ConnectException) at java.net.DualStackPlainSocketImpl/connect0 (DualStackPlainSocketImpl.java:-2).
Connection refused: connect

It had nothing to do with reading the file but with trying to reach a localhost:5001 instead of localhost:5000. Thanks for your support