Fork me on GitHub
#cljsrn
<
2023-02-24
>
Loic06:02:45

Hi all, I am using https://github.com/day8/re-frame-http-fx in my full stack clojure app (web and react native) using figwheel for the hot reloading. re-frame-http-fx and so the underlying cljs-ajax work fine in react with the uri as a relative path such as

{:http-xhrio {:uri "/pages/all"} ... }
However, when I try to use it in my react native frontend, all the exact same :http-xhrio works as expected but I have to use an absolute path uri instead such as:
{:http-xhrio {:uri ""} ... }
For web or mobile, I used fighweel with the embed ring server option on the default port 9500 How can I use the format "/pages/all" for mobile as well? I tried on ios with the Xcode simulator You can find the http-xhrio for the web https://github.com/skydread1/flybot.sg/blob/master/client/web/src/flybot/client/web/core/db/event.cljs#L26 and the http-xhrio for mobile https://github.com/skydread1/flybot.sg/blob/master/client/mobile/src/flybot/client/mobile/core/db/event.cljs#L16 Thank you

joshmiller18:02:36

I’m not sure that would ever work, because in an app you aren’t “on a page” where a relative path would make sense, right? On the mobile web, you are on a web page that the browser can use to construct an absolute path from a relative path, but in an app you aren’t on anything.

joshmiller18:02:27

What you could do is write a custom cofx that would automatically do it for you, so you’d have :localhost-http-xhrio { :uri "/pages/all" } that would construct the url and pass it along to the normal http-xhrio cofx.

Vincent T19:02:09

I am confused, re-frame-http-xhrio works from react native at all? Since cljs-ajax doesn’t use fetch I thought this wasn’t possible https://github.com/day8/re-frame-http-fx/issues/23

Vincent T20:02:16

That’s pretty cool - I will remember this next time

Loic03:02:11

@U0E1JV8GK Thank you for the clarification regarding the difference between web and mobile URIs shapes. I ended up using the google closure compiler option :https://clojurescript.org/reference/compiler-options#closure-defines which I can easily override with https://figwheel.org/docs/compile_config.html. Then my uri is just (str BASE-URI /pages/all) with BASE-URI being defines as (goog-define BASE-URI "") So it works for web and mobile but also dev and prod as well.