Fork me on GitHub
#reitit
<
2019-11-12
>
valerauko03:11:13

i use aleph, but i think most clojure http servers are ring-compatible

sudakatux11:11:03

Im having a strange problem, which i dont know why i did not came up before

sudakatux11:11:31

Im setting the not found to return always index

sudakatux11:11:46

So i can let the frontend take over the router portion

sudakatux11:11:50

{:not-found
       (constantly (response/ok (io/input-stream
                                  (io/resource "public/index.html"))))

sudakatux11:11:58

for some reason

sudakatux11:11:29

I get this error sometimes /create java.io.IOException: Stream closed

sudakatux11:11:37

when i want to hit /create

sudakatux11:11:47

which will normally fall in the not-found

sudakatux11:11:20

could not figure out the pattern yet as to why sometimes it throws the above warning and does noting

sudakatux11:11:51

it just returns blank

Toni Vanhala11:11:08

Here’s an example that serves the index.html with ring.util.response/resource-response https://github.com/metosin/reitit/blob/master/examples/frontend/src/backend/server.clj

Toni Vanhala11:11:11

I suspect you are getting IOException because you open the stream only once and try to serve it more than once

sudakatux11:11:07

Thank u verry much that solved my problem

sudakatux11:11:38

So i should not be serving resources the way I was doing?

ikitommi11:11:24

@jstuartmilne constantly calls the body once and returns always the same response. Second time you call the same endpoint, the Stream is already closed. Instead, you should re-create the stream for all request: (fn [_] (response/ok (io/input-stream (io/resource "public/index.html"))))

Toni Vanhala11:11:27

The example at Clojuredocs shows how constantly works in this case. https://clojuredocs.org/clojure.core/constantly

(map (constantly (rand-int 100)) [:a :b :c])
user=> (43 43 43)
The (rand-int 100) is evaluated only once.

sudakatux11:11:52

oh i see. thanks for the explanation